






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






  """simple docstring"""





  def __init__(     self		,		*_UpperCAmelCase		,		_UpperCAmelCase=None		,		_UpperCAmelCase=None		,		**_UpperCAmelCase )			-> str:
     super().__init__(*_UpperCAmelCase		,		**_UpperCAmelCase )
     UpperCamelCase_									=     eval_examples
     UpperCamelCase_									=     post_process_function




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase=None		,		_UpperCAmelCase=None		,		_UpperCAmelCase=None		,		_UpperCAmelCase = "eval" )			-> Dict:
     UpperCamelCase_									=     self.eval_dataset if eval_dataset is None else eval_dataset
     UpperCamelCase_									=     self.get_eval_dataloader(_UpperCAmelCase )
     UpperCamelCase_									=     self.eval_examples if eval_examples is None else eval_examples

     # Temporarily disable metric computation, we will do it in the loop here.
     UpperCamelCase_									=     self.compute_metrics
     UpperCamelCase_									=     None
     UpperCamelCase_									=     self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
     UpperCamelCase_									=     time.time()
     try:
        UpperCamelCase_									=     eval_loop(
            _UpperCAmelCase		,		description='Evaluation'		,		prediction_loss_only=True if compute_metrics is None else None		,		ignore_keys=_UpperCAmelCase		,		metric_key_prefix=_UpperCAmelCase		,		)
     finally:
        UpperCamelCase_									=     compute_metrics
     UpperCamelCase_									=     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(
             _UpperCAmelCase		,		_UpperCAmelCase		,		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_									=     self.post_process_function(_UpperCAmelCase		,		_UpperCAmelCase		,		output.predictions )
        UpperCamelCase_									=     self.compute_metrics(_UpperCAmelCase )

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

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

     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_									=     self.callback_handler.on_evaluate(self.args		,		self.state		,		self.control		,		_UpperCAmelCase )
     return metrics




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase=None		,		_UpperCAmelCase = "test" )			-> Union[str, Any]:
     UpperCamelCase_									=     self.get_test_dataloader(_UpperCAmelCase )

     # Temporarily disable metric computation, we will do it in the loop here.
     UpperCamelCase_									=     self.compute_metrics
     UpperCamelCase_									=     None
     UpperCamelCase_									=     self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
     UpperCamelCase_									=     time.time()
     try:
        UpperCamelCase_									=     eval_loop(
            _UpperCAmelCase		,		description='Prediction'		,		prediction_loss_only=True if compute_metrics is None else None		,		ignore_keys=_UpperCAmelCase		,		metric_key_prefix=_UpperCAmelCase		,		)
     finally:
        UpperCamelCase_									=     compute_metrics
     UpperCamelCase_									=     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(
             _UpperCAmelCase		,		_UpperCAmelCase		,		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_									=     self.post_process_function(_UpperCAmelCase		,		_UpperCAmelCase		,		output.predictions		,		'predict' )
     UpperCamelCase_									=     self.compute_metrics(_UpperCAmelCase )

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













snake_case__      :	List[Any]       	=      """Tobias Carryer"""

from time import time


class 						_a       :






  """simple docstring"""





  def __init__(     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase=int(time() ) )			-> Tuple:  # noqa: B008
     UpperCamelCase_									=     multiplier
     UpperCamelCase_									=     increment
     UpperCamelCase_									=     modulo
     UpperCamelCase_									=     seed




  def    _UpperCAmelCase     (     self )			-> Any:
     UpperCamelCase_									=     (self.multiplier * self.seed + self.increment) % self.modulo
     return self.seed


if __name__ == "__main__":
 # Show the LCG in action.
 snake_case__      :	List[Any]       	=      LinearCongruentialGenerator(1_6_6_4_5_2_5, 1_0_1_3_9_0_4_2_2_3, 2 << 3_1)
 while True:
  print(lcg.next_number())





