





import os
import tempfile
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
						import torch
						from torch import nn

						from transformers import (
						    Adafactor,
						    AdamW,
						    get_constant_schedule,
						    get_constant_schedule_with_warmup,
						    get_cosine_schedule_with_warmup,
						    get_cosine_with_hard_restarts_schedule_with_warmup,
						    get_inverse_sqrt_schedule,
						    get_linear_schedule_with_warmup,
						    get_polynomial_decay_schedule_with_warmup,
						)





def    __UpperCamelCase      (    a,     a=10) ->Optional[Any]:
					lowerCamelCase__       =       []
					for _ in range(a):
										lrs.append(scheduler.get_lr()[0])
										scheduler.step()
					return lrs





def    __UpperCamelCase      (    a,     a=10) ->Optional[int]:
					lowerCamelCase__       =       []
					for step in range(a):
										lrs.append(scheduler.get_lr()[0])
										scheduler.step()
										if step == num_steps // 2:
															with tempfile.TemporaryDirectory() as tmpdirname:
																				lowerCamelCase__       =       os.path.join(a,     "schedule.bin")
																				torch.save(scheduler.state_dict(),     a)

																				lowerCamelCase__       =       torch.load(a)
																				scheduler.load_state_dict(a)
					return lrs

@require_torch
class SCREAMING_SNAKE_CASE_ (					unittest.TestCase   ):





					"""simple docstring"""


					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase	,  _lowerCAmelCase	):
										self.assertEqual(len(UpperCamelCase__	)	,  len(UpperCamelCase__	)	)
										for a, b in zip(UpperCamelCase__	,  UpperCamelCase__	):
															self.assertAlmostEqual(UpperCamelCase__	,  UpperCamelCase__	,  delta=UpperCamelCase__	)





					def 					__magic_name__ ( self	):
										lowerCamelCase__       =       torch.tensor([0.1, -0.2, -0.1]	,  requires_grad=UpperCamelCase__	)
										lowerCamelCase__       =       torch.tensor([0.4, 0.2, -0.5]	)
										lowerCamelCase__       =       nn.MSELoss()
										# No warmup, constant schedule, no gradient clipping
										lowerCamelCase__       =       AdamW(params=[w]	,  lr=2E-1	,  weight_decay=0.0	)
										for _ in range(100	):
															lowerCamelCase__       =       criterion(UpperCamelCase__	,  UpperCamelCase__	)
															loss.backward()
															optimizer.step()
															w.grad.detach_()  # No zero_grad() function on simple tensors. we do it ourselves.
															w.grad.zero_()
										self.assertListAlmostEqual(w.tolist()	,  [0.4, 0.2, -0.5]	,  tol=1E-2	)






					def 					__magic_name__ ( self	):
										lowerCamelCase__       =       torch.tensor([0.1, -0.2, -0.1]	,  requires_grad=UpperCamelCase__	)
										lowerCamelCase__       =       torch.tensor([0.4, 0.2, -0.5]	)
										lowerCamelCase__       =       nn.MSELoss()
										# No warmup, constant schedule, no gradient clipping
										lowerCamelCase__       =       Adafactor(
										    params=[w]	,  lr=1E-2	,  eps=(1E-30, 1E-3)	,  clip_threshold=1.0	,  decay_rate=-0.8	,  betaa=UpperCamelCase__	,  weight_decay=0.0	,  relative_step=UpperCamelCase__	,  scale_parameter=UpperCamelCase__	,  warmup_init=UpperCamelCase__	,  )
										for _ in range(1000	):
															lowerCamelCase__       =       criterion(UpperCamelCase__	,  UpperCamelCase__	)
															loss.backward()
															optimizer.step()
															w.grad.detach_()  # No zero_grad() function on simple tensors. we do it ourselves.
															w.grad.zero_()
										self.assertListAlmostEqual(w.tolist()	,  [0.4, 0.2, -0.5]	,  tol=1E-2	)

@require_torch
class SCREAMING_SNAKE_CASE_ (					unittest.TestCase   ):





					"""simple docstring"""


					A__     :   List[Any]				 =    nn.Linear(5_0							,       5_0   ) if is_torch_available() else None
					A__     :   List[str]				 =    AdamW(m.parameters()							,       lr=10.0   ) if is_torch_available() else None
					A__     :   Optional[int]				 =    1_0





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase	,  _lowerCAmelCase	,  _lowerCAmelCase=None	):
										self.assertEqual(len(UpperCamelCase__	)	,  len(UpperCamelCase__	)	)
										for a, b in zip(UpperCamelCase__	,  UpperCamelCase__	):
															self.assertAlmostEqual(UpperCamelCase__	,  UpperCamelCase__	,  delta=UpperCamelCase__	,  msg=UpperCamelCase__	)






					def 					__magic_name__ ( self	):
										lowerCamelCase__       =       {"num_warmup_steps": 2, "num_training_steps": 10}
										# schedulers doct format
										# function: (sched_args_dict, expected_learning_rates)
										lowerCamelCase__       =       {
										    get_constant_schedule: ({}, [10.0] * self.num_steps),
										    get_constant_schedule_with_warmup: (
										        {"num_warmup_steps": 4},
										        [0.0, 2.5, 5.0, 7.5, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0],
										    ),
										    get_linear_schedule_with_warmup: (
										        {**common_kwargs},
										        [0.0, 5.0, 10.0, 8.75, 7.5, 6.25, 5.0, 3.75, 2.5, 1.25],
										    ),
										    get_cosine_schedule_with_warmup: (
										        {**common_kwargs},
										        [0.0, 5.0, 10.0, 9.61, 8.53, 6.91, 5.0, 3.08, 1.46, 0.38],
										    ),
										    get_cosine_with_hard_restarts_schedule_with_warmup: (
										        {**common_kwargs, "num_cycles": 2},
										        [0.0, 5.0, 10.0, 8.53, 5.0, 1.46, 10.0, 8.53, 5.0, 1.46],
										    ),
										    get_polynomial_decay_schedule_with_warmup: (
										        {**common_kwargs, "power": 2.0, "lr_end": 1E-7},
										        [0.0, 5.0, 10.0, 7.656, 5.625, 3.906, 2.5, 1.406, 0.625, 0.156],
										    ),
										    get_inverse_sqrt_schedule: (
										        {"num_warmup_steps": 2},
										        [0.0, 5.0, 10.0, 8.165, 7.071, 6.325, 5.774, 5.345, 5.0, 4.714],
										    ),
										}

										for scheduler_func, data in scheds.items():
															lowerCamelCase__    ,		lowerCamelCase__       =       data

															lowerCamelCase__       =       scheduler_func(self.optimizer	,  **UpperCamelCase__	)
															self.assertEqual(len([scheduler.get_lr()[0]]	)	,  1	)
															lowerCamelCase__       =       unwrap_schedule(UpperCamelCase__	,  self.num_steps	)
															self.assertListAlmostEqual(
															    UpperCamelCase__	,  UpperCamelCase__	,  tol=1E-2	,  msg=F"failed for {scheduler_func} in normal scheduler"	,  )

															lowerCamelCase__       =       scheduler_func(self.optimizer	,  **UpperCamelCase__	)
															if scheduler_func.__name__ != "get_constant_schedule":
																				LambdaScheduleWrapper.wrap_scheduler(UpperCamelCase__	)  # wrap to test picklability of the schedule
															lowerCamelCase__       =       unwrap_and_save_reload_schedule(UpperCamelCase__	,  self.num_steps	)
															self.assertListEqual(UpperCamelCase__	,  UpperCamelCase__	,  msg=F"failed for {scheduler_func} in save and reload"	)

class SCREAMING_SNAKE_CASE_ :





					"""simple docstring"""


					def __init__( self	,  _lowerCAmelCase	):
										lowerCamelCase__       =       fn





					def __call__( self	,  *_lowerCAmelCase	,  **_lowerCAmelCase	):
										return self.fn(*UpperCamelCase__	,  **UpperCamelCase__	)






					@classmethod
					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										lowerCamelCase__       =       list(map(self	,  scheduler.lr_lambdas	)	)








A_												=     {str(digit): digit**5 for digit in range(1_0)}





def    __UpperCamelCase      (    a) ->int:
					return sum(DIGITS_FIFTH_POWER[digit] for digit in str(a))





def    __UpperCamelCase      (    ) ->int:
					return sum(
					    number
					    for number in range(1000,     1000000)
					    if number == digits_fifth_powers_sum(a))


if __name__ == "__main__":
						print(solution())

