


'''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__       (						__lowercase      ):






      def __init__( self			:str     ,						*SCREAMING_SNAKE_CASE			:List[str]     ,						SCREAMING_SNAKE_CASE			:List[Any]=None     ,						SCREAMING_SNAKE_CASE			:Dict=None     ,						**SCREAMING_SNAKE_CASE			:Union[str, Any]	)       ->					Optional[Any]:




             '''simple docstring'''
             super().__init__(*_a     ,						**_a	)
             _a    : Any     					=eval_examples
             _a    : Optional[int]     					=post_process_function






      def __UpperCAmelCase       ( self			:int     ,						SCREAMING_SNAKE_CASE			:Optional[int]=None     ,						SCREAMING_SNAKE_CASE			:Optional[Any]=None     ,						SCREAMING_SNAKE_CASE			:Dict=None     ,						SCREAMING_SNAKE_CASE			:Optional[Any] = "eval"	)       ->					List[str]:




             '''simple docstring'''
             _a    : List[Any]     					=self.eval_dataset if eval_dataset is None else eval_dataset
             _a    : List[str]     					=self.get_eval_dataloader(_a	)
             _a    : Dict     					=self.eval_examples if eval_examples is None else eval_examples

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

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

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

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






      def __UpperCAmelCase       ( self			:int     ,						SCREAMING_SNAKE_CASE			:Optional[int]     ,						SCREAMING_SNAKE_CASE			:Any     ,						SCREAMING_SNAKE_CASE			:Union[str, Any]=None     ,						SCREAMING_SNAKE_CASE			:int = "test"	)       ->					Union[str, Any]:




             '''simple docstring'''
             _a    : str     					=self.get_test_dataloader(_a	)

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

             # 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(_a	)
             metrics.update(output.metrics	)
             return PredictionOutput(predictions=predictions.predictions     ,						label_ids=predictions.label_ids     ,						metrics=_a	)





from diffusers.utils.testing_utils import require_onnxruntime

@require_onnxruntime
class 				UpperCAmelCase_		:
							"""simple docstring"""







							pass



