



import shutil
import tempfile
import unittest
from unittest.mock import patch

from transformers import (
    DefaultFlowCallback,
    IntervalStrategy,
    PrinterCallback,
    ProgressCallback,
    Trainer,
    TrainerCallback,
    TrainingArguments,
    is_torch_available,
)
from transformers.testing_utils import require_torch


if is_torch_available():
							from transformers.trainer import DEFAULT_CALLBACKS

							from .test_trainer import RegressionDataset, RegressionModelConfig, RegressionPreTrainedModel
class 				_snake_case			(					lowercase__):




				def __init__(						self					:						List[Any]						):
							lowercase__					  =				[]




				def 							A__      (						self					:						Optional[int],					__lowercase					:						Any,					__lowercase					:						int,					__lowercase					:						str,					**__lowercase					:						Optional[Any]						):
							self.events.append("on_init_end"						)




				def 							A__      (						self					:						str,					__lowercase					:						Tuple,					__lowercase					:						Any,					__lowercase					:						Optional[Any],					**__lowercase					:						List[str]						):
							self.events.append("on_train_begin"						)




				def 							A__      (						self					:						Dict,					__lowercase					:						Optional[int],					__lowercase					:						Optional[Any],					__lowercase					:						List[Any],					**__lowercase					:						List[Any]						):
							self.events.append("on_train_end"						)




				def 							A__      (						self					:						Optional[int],					__lowercase					:						Optional[int],					__lowercase					:						int,					__lowercase					:						Union[str, Any],					**__lowercase					:						Optional[Any]						):
							self.events.append("on_epoch_begin"						)




				def 							A__      (						self					:						Optional[int],					__lowercase					:						Dict,					__lowercase					:						str,					__lowercase					:						List[str],					**__lowercase					:						Tuple						):
							self.events.append("on_epoch_end"						)




				def 							A__      (						self					:						Tuple,					__lowercase					:						Tuple,					__lowercase					:						str,					__lowercase					:						List[Any],					**__lowercase					:						Any						):
							self.events.append("on_step_begin"						)




				def 							A__      (						self					:						Tuple,					__lowercase					:						List[str],					__lowercase					:						Dict,					__lowercase					:						List[Any],					**__lowercase					:						Optional[int]						):
							self.events.append("on_step_end"						)




				def 							A__      (						self					:						List[Any],					__lowercase					:						Optional[Any],					__lowercase					:						Union[str, Any],					__lowercase					:						Optional[Any],					**__lowercase					:						Optional[Any]						):
							self.events.append("on_evaluate"						)




				def 							A__      (						self					:						Any,					__lowercase					:						Union[str, Any],					__lowercase					:						Optional[int],					__lowercase					:						str,					**__lowercase					:						List[Any]						):
							self.events.append("on_predict"						)




				def 							A__      (						self					:						Union[str, Any],					__lowercase					:						Union[str, Any],					__lowercase					:						List[str],					__lowercase					:						List[str],					**__lowercase					:						Tuple						):
							self.events.append("on_save"						)




				def 							A__      (						self					:						int,					__lowercase					:						Dict,					__lowercase					:						Tuple,					__lowercase					:						Union[str, Any],					**__lowercase					:						Optional[Any]						):
							self.events.append("on_log"						)




				def 							A__      (						self					:						Dict,					__lowercase					:						List[Any],					__lowercase					:						Union[str, Any],					__lowercase					:						Optional[Any],					**__lowercase					:						Optional[Any]						):
							self.events.append("on_prediction_step"						)
@require_torch
class 				_snake_case			(					unittest.TestCase):




				def 							A__      (						self					:						str						):
							lowercase__					  =				tempfile.mkdtemp()




				def 							A__      (						self					:						Optional[Any]						):
							shutil.rmtree(self.output_dir						)




				def 							A__      (						self					:						Optional[int],					__lowercase					:						int=0,					__lowercase					:						Optional[Any]=0,					__lowercase					:						Union[str, Any]=64,					__lowercase					:						int=64,					__lowercase					:						str=None,					__lowercase					:						Union[str, Any]=False,					**__lowercase					:						Tuple						):
							# disable_tqdm in TrainingArguments has a flaky default since it depends on the level of logging. We make sure
							# its set to False since the tests later on depend on its value.
							lowercase__					  =				RegressionDataset(length=__lowercase						)
							lowercase__					  =				RegressionDataset(length=__lowercase						)
							lowercase__					  =				RegressionModelConfig(a=__lowercase,					b=__lowercase						)
							lowercase__					  =				RegressionPreTrainedModel(__lowercase						)

							lowercase__					  =				TrainingArguments(self.output_dir,					disable_tqdm=__lowercase,					report_to=[],					**__lowercase						)
							return Trainer(
							    __lowercase,					__lowercase,					train_dataset=__lowercase,					eval_dataset=__lowercase,					callbacks=__lowercase,					)




				def 							A__      (						self					:						Any,					__lowercase					:						str,					__lowercase					:						Any						):
							self.assertEqual(len(__lowercase						),					len(__lowercase						)						)

							# Order doesn't matter
							lowercase__					  =				sorted(__lowercase,					key=lambda __lowercase						: cb.__name__ if isinstance(__lowercase,					__lowercase						) else cb.__class__.__name__						)
							lowercase__					  =				sorted(__lowercase,					key=lambda __lowercase						: cb.__name__ if isinstance(__lowercase,					__lowercase						) else cb.__class__.__name__						)

							for cba, cba in zip(__lowercase,					__lowercase						):
										if isinstance(__lowercase,					__lowercase						) and isinstance(__lowercase,					__lowercase						):
													self.assertEqual(__lowercase,					__lowercase						)
										elif isinstance(__lowercase,					__lowercase						) and not isinstance(__lowercase,					__lowercase						):
													self.assertEqual(__lowercase,					cba.__class__						)
										elif not isinstance(__lowercase,					__lowercase						) and isinstance(__lowercase,					__lowercase						):
													self.assertEqual(cba.__class__,					__lowercase						)
										else:
													self.assertEqual(__lowercase,					__lowercase						)




				def 							A__      (						self					:						str,					__lowercase					:						Dict						):
							lowercase__					  =				["on_init_end", "on_train_begin"]
							lowercase__					  =				0
							lowercase__					  =				len(trainer.get_eval_dataloader()						)
							lowercase__					  =				["on_prediction_step"] * len(trainer.get_eval_dataloader()						) + ["on_log", "on_evaluate"]
							for _ in range(trainer.state.num_train_epochs						):
										expected_events.append("on_epoch_begin"						)
										for _ in range(__lowercase						):
													step += 1
													expected_events += ["on_step_begin", "on_step_end"]
													if step % trainer.args.logging_steps == 0:
																expected_events.append("on_log"						)
													if trainer.args.evaluation_strategy == IntervalStrategy.STEPS and step % trainer.args.eval_steps == 0:
																expected_events += evaluation_events.copy()
													if step % trainer.args.save_steps == 0:
																expected_events.append("on_save"						)
										expected_events.append("on_epoch_end"						)
										if trainer.args.evaluation_strategy == IntervalStrategy.EPOCH:
													expected_events += evaluation_events.copy()
							expected_events += ["on_log", "on_train_end"]
							return expected_events




				def 							A__      (						self					:						str						):
							lowercase__					  =				self.get_trainer()
							lowercase__					  =				DEFAULT_CALLBACKS.copy() + [ProgressCallback]
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)

							# Callbacks passed at init are added to the default callbacks
							lowercase__					  =				self.get_trainer(callbacks=[MyTestTrainerCallback]						)
							expected_callbacks.append(__lowercase						)
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)

							# TrainingArguments.disable_tqdm controls if use ProgressCallback or PrinterCallback
							lowercase__					  =				self.get_trainer(disable_tqdm=__lowercase						)
							lowercase__					  =				DEFAULT_CALLBACKS.copy() + [PrinterCallback]
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)




				def 							A__      (						self					:						Dict						):
							lowercase__					  =				DEFAULT_CALLBACKS.copy() + [ProgressCallback]
							lowercase__					  =				self.get_trainer()

							# We can add, pop, or remove by class name
							trainer.remove_callback(__lowercase						)
							expected_callbacks.remove(__lowercase						)
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)

							lowercase__					  =				self.get_trainer()
							lowercase__					  =				trainer.pop_callback(__lowercase						)
							self.assertEqual(cb.__class__,					__lowercase						)
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)

							trainer.add_callback(__lowercase						)
							expected_callbacks.insert(0,					__lowercase						)
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)

							# We can also add, pop, or remove by instance
							lowercase__					  =				self.get_trainer()
							lowercase__					  =				trainer.callback_handler.callbacks[0]
							trainer.remove_callback(__lowercase						)
							expected_callbacks.remove(__lowercase						)
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)

							lowercase__					  =				self.get_trainer()
							lowercase__					  =				trainer.callback_handler.callbacks[0]
							lowercase__					  =				trainer.pop_callback(__lowercase						)
							self.assertEqual(__lowercase,					__lowercase						)
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)

							trainer.add_callback(__lowercase						)
							expected_callbacks.insert(0,					__lowercase						)
							self.check_callbacks_equality(trainer.callback_handler.callbacks,					__lowercase						)




				def 							A__      (						self					:						Union[str, Any]						):
							import warnings

							# XXX: for now ignore scatter_gather warnings in this test since it's not relevant to what's being tested
							warnings.simplefilter(action="ignore",					category=__lowercase						)

							lowercase__					  =				self.get_trainer(callbacks=[MyTestTrainerCallback]						)
							trainer.train()
							lowercase__					  =				trainer.callback_handler.callbacks[-2].events
							self.assertEqual(__lowercase,					self.get_expected_events(__lowercase						)						)

							# Independent log/save/eval
							lowercase__					  =				self.get_trainer(callbacks=[MyTestTrainerCallback],					logging_steps=5						)
							trainer.train()
							lowercase__					  =				trainer.callback_handler.callbacks[-2].events
							self.assertEqual(__lowercase,					self.get_expected_events(__lowercase						)						)

							lowercase__					  =				self.get_trainer(callbacks=[MyTestTrainerCallback],					save_steps=5						)
							trainer.train()
							lowercase__					  =				trainer.callback_handler.callbacks[-2].events
							self.assertEqual(__lowercase,					self.get_expected_events(__lowercase						)						)

							lowercase__					  =				self.get_trainer(callbacks=[MyTestTrainerCallback],					eval_steps=5,					evaluation_strategy="steps"						)
							trainer.train()
							lowercase__					  =				trainer.callback_handler.callbacks[-2].events
							self.assertEqual(__lowercase,					self.get_expected_events(__lowercase						)						)

							lowercase__					  =				self.get_trainer(callbacks=[MyTestTrainerCallback],					evaluation_strategy="epoch"						)
							trainer.train()
							lowercase__					  =				trainer.callback_handler.callbacks[-2].events
							self.assertEqual(__lowercase,					self.get_expected_events(__lowercase						)						)

							# A bit of everything
							lowercase__					  =				self.get_trainer(
							    callbacks=[MyTestTrainerCallback],					logging_steps=3,					save_steps=10,					eval_steps=5,					evaluation_strategy="steps",					)
							trainer.train()
							lowercase__					  =				trainer.callback_handler.callbacks[-2].events
							self.assertEqual(__lowercase,					self.get_expected_events(__lowercase						)						)

							# warning should be emitted for duplicated callbacks
							with patch("transformers.trainer_callback.logger.warning"						) as warn_mock:
										lowercase__					  =				self.get_trainer(
										    callbacks=[MyTestTrainerCallback, MyTestTrainerCallback],					)
										assert str(__lowercase						) in warn_mock.call_args[0][0]









import math



def __lowerCAmelCase (     SCREAMING_SNAKE_CASE_						,  SCREAMING_SNAKE_CASE_  ):
			if 0 not in (x, y):
						# We use the relation x^y = y*log10(x), where 10 is the base.
						return y * math.logaa(SCREAMING_SNAKE_CASE_  )
			else:
						if x == 0:  # 0 raised to any number is 0
									return 0
						elif y == 0:
									return 1  # any number raised to 0 is 1
			raise AssertionError("This should never happen"  )


if __name__ == "__main__":  # Main function
							# Read two numbers from input and typecast them to int using map function.
							# Here x is the base and y is the power.
							lowercase_								=     """Enter the base and the power separated by a comma: """
							lowercase_				,    lowercase_								=     map(int, input(prompt).split(""","""))
							lowercase_				,    lowercase_								=     map(int, input(prompt).split(""","""))

							# We find the log of each number, using the function res(), which takes two
							# arguments.
							lowercase_								=     res(xa, ya)
							lowercase_								=     res(xa, ya)

							# We check for the largest number
							if resa > resa:
														print("""Largest number is""", xa, """^""", ya)
							elif resa > resa:
														print("""Largest number is""", xa, """^""", ya)
							else:
														print("""Both are equal""")




