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







							def __init__(				self     :    Union[str, Any]	,					*__snake_case     :    str	,					__snake_case     :    Any=None	,					__snake_case     :    Any=None	,					**__snake_case     :    Union[str, Any]		):
										super().__init__(*_lowerCAmelCase	,					**_lowerCAmelCase		)
										lowerCamelCase						:List[str]						  =     eval_examples
										lowerCamelCase						:Optional[Any]						  =     post_process_function







							def 				snake_case  (				self     :    List[str]	,					__snake_case     :    Dict = None	,					__snake_case     :    List[str]=None	,					__snake_case     :    List[Any] = None	,					__snake_case     :    List[Any] = "eval"	,					**__snake_case     :    Optional[int]	,					):
										lowerCamelCase						:Optional[int]						  =     gen_kwargs.copy()
										lowerCamelCase						:List[Any]						  =     (
										    gen_kwargs['''max_length'''] if gen_kwargs.get('''max_length'''		) is not None else self.args.generation_max_length
										)
										lowerCamelCase						:List[str]						  =     (
										    gen_kwargs['''num_beams'''] if gen_kwargs.get('''num_beams'''		) is not None else self.args.generation_num_beams
										)
										lowerCamelCase						:str						  =     gen_kwargs

										lowerCamelCase						:Optional[int]						  =     self.eval_dataset if eval_dataset is None else eval_dataset
										lowerCamelCase						:str						  =     self.get_eval_dataloader(_lowerCAmelCase		)
										lowerCamelCase						:List[Any]						  =     self.eval_examples if eval_examples is None else eval_examples

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

													metrics.update(output.metrics		)
										else:
													lowerCamelCase						:Optional[Any]						  =     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()		)

										lowerCamelCase						:Any						  =     self.callback_handler.on_evaluate(self.args	,					self.state	,					self.control	,					_lowerCAmelCase		)
										return metrics







							def 				snake_case  (				self     :    Any	,					__snake_case     :    Union[str, Any]	,					__snake_case     :    Dict	,					__snake_case     :    List[Any]=None	,					__snake_case     :    Dict = "test"	,					**__snake_case     :    str		):
										lowerCamelCase						:Optional[Any]						  =     gen_kwargs.copy()

										lowerCamelCase						:Any						  =     self.get_test_dataloader(_lowerCAmelCase		)

										# Temporarily disable metric computation, we will do it in the loop here.
										lowerCamelCase						:str						  =     self.compute_metrics
										lowerCamelCase						:Optional[int]						  =     None
										lowerCamelCase						:Union[str, Any]						  =     time.time()
										lowerCamelCase						:str						  =     self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
										try:
													lowerCamelCase						: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:
													lowerCamelCase						:List[str]						  =     compute_metrics

										lowerCamelCase						: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

										lowerCamelCase						:int						  =     self.post_process_function(_lowerCAmelCase	,					_lowerCAmelCase	,					_lowerCAmelCase	,					'''predict'''		)
										lowerCamelCase						:Tuple						  =     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}_"		):
																lowerCamelCase						:int						  =     metrics.pop(_lowerCAmelCase		)
										metrics.update(output.metrics		)
										return PredictionOutput(predictions=predictions.predictions	,					label_ids=predictions.label_ids	,					metrics=_lowerCAmelCase		)




def  _lowerCamelCase					(   a_				: int = 4_00_00_00):
			lowerCamelCase						:Dict						  =     [0, 1]
			lowerCamelCase						:Optional[Any]						  =     0
			while fib[i] <= n:
						fib.append(fib[i] + fib[i + 1])
						if fib[i + 2] > n:
									break
						i += 1
			lowerCamelCase						:Dict						  =     0
			for j in range(len(a_) - 1):
						if fib[j] % 2 == 0:
									total += fib[j]

			return total


if __name__ == "__main__":
			print(F'{solution() = }')



