






import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
							import tensorflow as tf
							from tensorflow.python.eager import context
							from tensorflow.python.framework import ops

							from transformers import GradientAccumulator, create_optimizer
@require_tf
class    _UpperCAmelCase      ( unittest.TestCase			):

				"""simple docstring"""




				def        lowercase__     (  self		:					Tuple,						lowerCamelCase		:					List[Any],						lowerCamelCase		:					Optional[int],						lowerCamelCase		:					Any						):

								'''simple docstring'''
								self.assertEqual(len(lowerCamelCase						),						len(lowerCamelCase						)						)
								for a, b in zip(lowerCamelCase,						lowerCamelCase						):
												self.assertAlmostEqual(lowerCamelCase,						lowerCamelCase,						delta=lowerCamelCase						)




				def        lowercase__     (  self		:					Any						):

								'''simple docstring'''
								lowercase__     				=    GradientAccumulator()
								accumulator([tf.constant([1.0, 2.0]						)]						)
								accumulator([tf.constant([-2.0, 1.0]						)]						)
								accumulator([tf.constant([-1.0, 2.0]						)]						)
								with self.assertRaises(lowerCamelCase						):
												accumulator([tf.constant([1.0, 1.0]						), tf.constant([2.0, 2.0]						)]						)
								self.assertEqual(accumulator.step,						3						)
								self.assertEqual(len(accumulator.gradients						),						1						)
								self.assertListAlmostEqual(accumulator.gradients[0].numpy().tolist(),						[-2.0, 5.0],						tol=1E-2						)
								accumulator.reset()
								self.assertEqual(accumulator.step,						0						)
								self.assertListAlmostEqual(accumulator.gradients[0].numpy().tolist(),						[0.0, 0.0],						tol=1E-2						)




				def        lowercase__     (  self		:					Optional[int]						):

								'''simple docstring'''
								lowercase__     				=    None
								ops.enable_eager_execution_internal()
								lowercase__     				=    tf.config.list_physical_devices('''CPU'''						)
								if len(lowerCamelCase						) == 1:
												tf.config.set_logical_device_configuration(
												    physical_devices[0],						[tf.config.LogicalDeviceConfiguration(), tf.config.LogicalDeviceConfiguration()]						)
								lowercase__     				=    tf.config.list_logical_devices(device_type='''CPU'''						)
								lowercase__     				=    tf.distribute.MirroredStrategy(devices=devices[:2]						)

								with strategy.scope():
												lowercase__     				=    GradientAccumulator()
												lowercase__     				=    tf.Variable([4.0, 3.0]						)
												lowercase__				,		lowercase__     				=    create_optimizer(5E-5,						10,						5						)
												lowercase__     				=    tf.Variable([0.0, 0.0],						trainable=lowerCamelCase						)

								def accumulate_on_replica(lowerCamelCase		:					Tuple						):
												accumulator([gradient]						)

								def apply_on_replica():
												optimizer.apply_gradients(list(zip(accumulator.gradients,						[variable]						)						)						)

								@tf.function
								def accumulate(lowerCamelCase		:					str,						lowerCamelCase		:					Optional[Any]						):
												with strategy.scope():
																lowercase__     				=    strategy.experimental_local_results(lowerCamelCase						)
																local_variables[0].assign(lowerCamelCase						)
																local_variables[1].assign(lowerCamelCase						)
																strategy.run(lowerCamelCase,						args=(gradient_placeholder,)						)

								@tf.function
								def apply_grad():
												with strategy.scope():
																strategy.run(lowerCamelCase						)

								def _check_local_values(lowerCamelCase		:					Dict,						lowerCamelCase		:					Optional[Any]						):
												lowercase__     				=    strategy.experimental_local_results(accumulator._gradients[0]						)
												self.assertListAlmostEqual(values[0].value(),						lowerCamelCase,						tol=1E-2						)
												self.assertListAlmostEqual(values[1].value(),						lowerCamelCase,						tol=1E-2						)

								accumulate([1.0, 2.0],						[-1.0, 1.0]						)
								accumulate([3.0, -1.0],						[-1.0, -1.0]						)
								accumulate([-2.0, 2.0],						[3.0, -2.0]						)
								self.assertEqual(accumulator.step,						3						)
								_check_local_values([2.0, 3.0],						[1.0, -2.0]						)
								apply_grad()
								self.assertListAlmostEqual(variable.value(),						[4.0, 3.0],						tol=1E-2						)
								accumulator.reset()
								self.assertEqual(accumulator.step,						0						)
								_check_local_values([0.0, 0.0],						[0.0, 0.0]						)












from functools import reduce

A__			:    Union[str, Any]         =				(
    '73167176531330624919225119674426574742355349194934'
    '96983520312774506326239578318016984801869478851843'
    '85861560789112949495459501737958331952853208805511'
    '12540698747158523863050715693290963295227443043557'
    '66896648950445244523161731856403098711121722383113'
    '62229893423380308135336276614282806444486645238749'
    '30358907296290491560440772390713810515859307960866'
    '70172427121883998797908792274921901699720888093776'
    '65727333001053367881220235421809751254540594752243'
    '52584907711670556013604839586446706324415722155397'
    '53697817977846174064955149290862569321978468622482'
    '83972241375657056057490261407972968652414535100474'
    '82166370484403199890008895243450658541227588666881'
    '16427171479924442928230863465674813919123162824586'
    '17866458359124566529476545682848912883142607690042'
    '24219022671055626321111109370544217506941658960408'
    '07198403850962455444362981230987879927244284909188'
    '84580156166097919133875499200524063689912560717606'
    '05886116467109405077541002256983155200055935729725'
    '71636269561882670428252483600823257530420752963450'
)






def 						a    (		lowerCamelCase_ = N       ):






				'''simple docstring'''
				return max(
				    # mypy cannot properly interpret reduce
				    int(reduce(lambda lowerCamelCase_	,     lowerCamelCase_       : str(int(lowerCamelCase_       ) * int(lowerCamelCase_       )       )	,     n[i : i + 13]       )       )
				    for i in range(len(lowerCamelCase_       ) - 12       )       )


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




