

"""simple docstring"""




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 			lowercase    (	lowercase_      ):




				def __init__( self				,       *snake_case				,       snake_case=None				,       snake_case=None				,       **snake_case	):
											super().__init__(*snake_case				,       **snake_case	)
											snake_case_          =   eval_examples
											snake_case_          =   post_process_function




				def    a							( self				,       snake_case = None				,       snake_case=None				,       snake_case = None				,       snake_case = "eval"				,       **snake_case				,       ):
											snake_case_          =   gen_kwargs.copy()
											snake_case_          =   (
											    gen_kwargs['max_length'] if gen_kwargs.get('max_length'	) is not None else self.args.generation_max_length
											)
											snake_case_          =   (
											    gen_kwargs['num_beams'] if gen_kwargs.get('num_beams'	) is not None else self.args.generation_num_beams
											)
											snake_case_          =   gen_kwargs

											snake_case_          =   self.eval_dataset if eval_dataset is None else eval_dataset
											snake_case_          =   self.get_eval_dataloader(snake_case	)
											snake_case_          =   self.eval_examples if eval_examples is None else eval_examples

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

																		# Prefix all keys with metric_key_prefix + '_'
																		for key in list(metrics.keys()	):
																									if not key.startswith(F'''{metric_key_prefix}_'''	):
																																snake_case_          =   metrics.pop(snake_case	)

																		metrics.update(output.metrics	)
											else:
																		snake_case_          =   output.metrics

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

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

											snake_case_          =   self.callback_handler.on_evaluate(self.args				,       self.state				,       self.control				,       snake_case	)
											return metrics




				def    a							( self				,       snake_case				,       snake_case				,       snake_case=None				,       snake_case = "test"				,       **snake_case	):
											snake_case_          =   gen_kwargs.copy()

											snake_case_          =   self.get_test_dataloader(snake_case	)

											# Temporarily disable metric computation, we will do it in the loop here.
											snake_case_          =   self.compute_metrics
											snake_case_          =   None
											snake_case_          =   time.time()
											snake_case_          =   self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
											try:
																		snake_case_          =   eval_loop(
																		    snake_case				,       description='Prediction'				,       prediction_loss_only=True if compute_metrics is None else None				,       ignore_keys=snake_case				,       metric_key_prefix=snake_case				,       )
											finally:
																		snake_case_          =   compute_metrics

											snake_case_          =   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(
											        snake_case				,       snake_case				,       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

											snake_case_          =   self.post_process_function(snake_case				,       snake_case				,       snake_case				,       'predict'	)
											snake_case_          =   self.compute_metrics(snake_case	)

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







from __future__ import annotations





def  __lowerCamelCase     (			UpperCamelCase__       ,							UpperCamelCase__				):







							'''simple docstring'''






							snake_case_          =   []
							create_all_state(1       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							[]       ,							UpperCamelCase__				)
							return result





def  __lowerCamelCase     (			UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							):







							'''simple docstring'''






							if level == 0:
														total_list.append(current_list[:]				)
														return

							for i in range(UpperCamelCase__       ,							total_number - level + 2				):
														current_list.append(UpperCamelCase__				)
														create_all_state(i + 1       ,							UpperCamelCase__       ,							level - 1       ,							UpperCamelCase__       ,							UpperCamelCase__				)
														current_list.pop()





def  __lowerCamelCase     (			UpperCamelCase__				):







							'''simple docstring'''






							for i in total_list:
														print(*UpperCamelCase__				)


if __name__ == "__main__":
					_UpperCAmelCase		:       str						    =	4
					_UpperCAmelCase		:       Tuple						    =	2
					_UpperCAmelCase		:       Optional[int]						    =	generate_all_combinations(n, k)
					print_all_state(total_list)




