


'''simple docstring'''
import inspect
import math
import tempfile
import unittest

import numpy as np

from transformers import ViTMAEConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch
		from torch import nn

		from transformers import ViTMAEForPreTraining, ViTMAEModel
		from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import ViTImageProcessor
class      lowercase			:

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_=13					,     UpperCamelCase_=30					,     UpperCamelCase_=2					,     UpperCamelCase_=3					,     UpperCamelCase_=True					,     UpperCamelCase_=True					,     UpperCamelCase_=32					,     UpperCamelCase_=5					,     UpperCamelCase_=4					,     UpperCamelCase_=37					,     UpperCamelCase_="gelu"					,     UpperCamelCase_=0.1					,     UpperCamelCase_=0.1					,     UpperCamelCase_=10					,     UpperCamelCase_=0.02					,     UpperCamelCase_=3					,     UpperCamelCase_=0.6					,     UpperCamelCase_=None					,     ):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				parent
							UpperCamelCase__     :Optional[int]							      =				batch_size
							UpperCamelCase__     :Optional[Any]							      =				image_size
							UpperCamelCase__     :List[str]							      =				patch_size
							UpperCamelCase__     :Union[str, Any]							      =				num_channels
							UpperCamelCase__     :Optional[Any]							      =				is_training
							UpperCamelCase__     :Optional[int]							      =				use_labels
							UpperCamelCase__     :Union[str, Any]							      =				hidden_size
							UpperCamelCase__     :Dict							      =				num_hidden_layers
							UpperCamelCase__     :Optional[int]							      =				num_attention_heads
							UpperCamelCase__     :Tuple							      =				intermediate_size
							UpperCamelCase__     :Optional[Any]							      =				hidden_act
							UpperCamelCase__     :List[Any]							      =				hidden_dropout_prob
							UpperCamelCase__     :str							      =				attention_probs_dropout_prob
							UpperCamelCase__     :List[str]							      =				type_sequence_label_size
							UpperCamelCase__     :int							      =				initializer_range
							UpperCamelCase__     :Any							      =				mask_ratio
							UpperCamelCase__     :Optional[Any]							      =				scope

							# in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
							# (we add 1 for the [CLS] token)
							UpperCamelCase__     :Optional[Any]							      =				(image_size // patch_size) ** 2
							UpperCamelCase__     :Tuple							      =				int(math.ceil((1 - mask_ratio) * (num_patches + 1)							)							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[Any]							      =				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

							UpperCamelCase__     :Union[str, Any]							      =				None
							if self.use_labels:
												UpperCamelCase__     :int							      =				ids_tensor([self.batch_size]					,     self.type_sequence_label_size							)

							UpperCamelCase__     :Optional[Any]							      =				self.get_config()

							return config, pixel_values, labels




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return ViTMAEConfig(
							    image_size=self.image_size					,     patch_size=self.patch_size					,     num_channels=self.num_channels					,     hidden_size=self.hidden_size					,     num_hidden_layers=self.num_hidden_layers					,     num_attention_heads=self.num_attention_heads					,     intermediate_size=self.intermediate_size					,     hidden_act=self.hidden_act					,     hidden_dropout_prob=self.hidden_dropout_prob					,     attention_probs_dropout_prob=self.attention_probs_dropout_prob					,     is_decoder=__a					,     initializer_range=self.initializer_range					,     mask_ratio=self.mask_ratio					,     )




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				ViTMAEModel(config=__a							)
							model.to(__a							)
							model.eval()
							UpperCamelCase__     :Optional[int]							      =				model(__a							)
							self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, self.seq_length, self.hidden_size)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				ViTMAEForPreTraining(__a							)
							model.to(__a							)
							model.eval()
							UpperCamelCase__     :Any							      =				model(__a							)
							UpperCamelCase__     :Dict							      =				(self.image_size // self.patch_size) ** 2
							UpperCamelCase__     :str							      =				self.patch_size**2 * self.num_channels
							self.parent.assertEqual(result.logits.shape					,     (self.batch_size, num_patches, expected_num_channels)							)

							# test greyscale images
							UpperCamelCase__     :int							      =				1
							UpperCamelCase__     :str							      =				ViTMAEForPreTraining(__a							)
							model.to(__a							)
							model.eval()
							UpperCamelCase__     :Union[str, Any]							      =				floats_tensor([self.batch_size, 1, self.image_size, self.image_size]							)
							UpperCamelCase__     :List[str]							      =				model(__a							)
							UpperCamelCase__     :Optional[Any]							      =				self.patch_size**2
							self.parent.assertEqual(result.logits.shape					,     (self.batch_size, num_patches, expected_num_channels)							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[int]							      =				self.prepare_config_and_inputs()
							UpperCamelCase__     :int							      =				config_and_inputs
							UpperCamelCase__     :Union[str, Any]							      =				{"""pixel_values""": pixel_values}
							return config, inputs_dict



@require_torch
class      lowercase			(							__lowercase			,	__lowercase			,	unittest.TestCase      ):

		"""simple docstring"""

		_a									=       (ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else ()
		_a									=       {'''feature-extraction''': ViTMAEModel} if is_torch_available() else {}

		_a									=       False
		_a									=       False
		_a									=       False
		_a									=       False




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				ViTMAEModelTester(self							)
							UpperCamelCase__     :List[Any]							      =				ConfigTester(self					,     config_class=__a					,     has_text_modality=__a					,     hidden_size=37							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		@unittest.skip(reason='''ViTMAE does not use inputs_embeds'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__     :Any							      =				model_class(__a							)
												self.assertIsInstance(model.get_input_embeddings()					,     (nn.Module)							)
												UpperCamelCase__     :Dict							      =				model.get_output_embeddings()
												self.assertTrue(x is None or isinstance(__a					,     nn.Linear							)							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[int]							      =				self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__     :List[str]							      =				model_class(__a							)
												UpperCamelCase__     :Union[str, Any]							      =				inspect.signature(model.forward							)
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												UpperCamelCase__     :List[Any]							      =				[*signature.parameters.keys()]

												UpperCamelCase__     :List[str]							      =				["""pixel_values"""]
												self.assertListEqual(arg_names[:1]					,     __a							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__a							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[Any]							      =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*__a							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							np.random.seed(2							)

							UpperCamelCase__     :str							      =				int((pt_model.config.image_size // pt_model.config.patch_size) ** 2							)
							UpperCamelCase__     :Optional[int]							      =				np.random.uniform(size=(self.model_tester.batch_size, num_patches)							)
							UpperCamelCase__     :Optional[int]							      =				torch.from_numpy(__a							)

							# Add `noise` argument.
							# PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
							UpperCamelCase__     :Any							      =				pt_noise

							super().check_pt_tf_models(__a					,     __a					,     __a							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__     :Any							      =				model_class(__a							)
												model.to(__a							)
												model.eval()
												# make random mask reproducible
												torch.manual_seed(2							)
												with torch.no_grad():
																	UpperCamelCase__     :List[str]							      =				model(**self._prepare_for_class(__a					,     __a							)							)

												UpperCamelCase__     :Dict							      =				outputs[0].cpu().numpy()
												UpperCamelCase__     :Dict							      =				0

												with tempfile.TemporaryDirectory() as tmpdirname:
																	model.save_pretrained(__a							)
																	UpperCamelCase__     :Dict							      =				model_class.from_pretrained(__a							)
																	model.to(__a							)
																	# make random mask reproducible
																	torch.manual_seed(2							)
																	with torch.no_grad():
																						UpperCamelCase__     :Optional[int]							      =				model(**self._prepare_for_class(__a					,     __a							)							)

																	# Make sure we don't have nans
																	UpperCamelCase__     :List[str]							      =				after_outputs[0].cpu().numpy()
																	UpperCamelCase__     :Optional[Any]							      =				0
																	UpperCamelCase__     :List[str]							      =				np.amax(np.abs(out_a - out_a							)							)
																	self.assertLessEqual(__a					,     1e-5							)




		@unittest.skip(
		    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip(
		    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip(
		    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip(reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCamelCase__     :List[str]							      =				ViTMAEModel.from_pretrained(__a							)
												self.assertIsNotNone(__a							)



def     a   (    )						->			List[str]:



					'''simple docstring'''






					UpperCamelCase__     :str							      =				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''     )
					return image







@require_torch
@require_vision
class      lowercase			(							unittest.TestCase      ):

		"""simple docstring"""

		@cached_property
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return ViTImageProcessor.from_pretrained('''facebook/vit-mae-base'''							) if is_vision_available() else None




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							np.random.seed(2							)

							UpperCamelCase__     :int							      =				ViTMAEForPreTraining.from_pretrained('''facebook/vit-mae-base'''							).to(__a							)

							UpperCamelCase__     :Tuple							      =				self.default_image_processor
							UpperCamelCase__     :Dict							      =				prepare_img()
							UpperCamelCase__     :List[Any]							      =				image_processor(images=__a					,     return_tensors='''pt'''							).to(__a							)

							# prepare a noise vector that will be also used for testing the TF model
							# (this way we can ensure that the PT and TF models operate on the same inputs)
							UpperCamelCase__     :Tuple							      =				ViTMAEConfig()
							UpperCamelCase__     :List[Any]							      =				int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2							)
							UpperCamelCase__     :Union[str, Any]							      =				np.random.uniform(size=(1, num_patches)							)

							# forward pass
							with torch.no_grad():
												UpperCamelCase__     :Union[str, Any]							      =				model(**__a					,     noise=torch.from_numpy(__a							).to(device=__a							)							)

							# verify the logits
							UpperCamelCase__     :int							      =				torch.Size((1, 196, 768)							)
							self.assertEqual(outputs.logits.shape					,     __a							)

							UpperCamelCase__     :str							      =				torch.tensor(
							    [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]							)

							self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]					,     expected_slice.to(__a							)					,     atol=1e-4							)							)



'''simple docstring'''
import sys

__snake_case							   =  (
    '''73167176531330624919225119674426574742355349194934'''
    '''96983520312774506326239578318016984801869478851843'''
    '''85861560789112949495459501737958331952853208805511'''
    '''12540698747158523863050715693290963295227443043557'''
    '''66896648950445244523161731856403098711121722383113'''
    '''62229893423380308135336276614282806444486645238749'''
    '''30358907296290491560440772390713810515859307960866'''
    '''70172427121883998797908792274921901699720888093776'''
    '''65727333001053367881220235421809751254540594752243'''
    '''52584907711670556013604839586446706324415722155397'''
    '''53697817977846174064955149290862569321978468622482'''
    '''83972241375657056057490261407972968652414535100474'''
    '''82166370484403199890008895243450658541227588666881'''
    '''16427171479924442928230863465674813919123162824586'''
    '''17866458359124566529476545682848912883142607690042'''
    '''24219022671055626321111109370544217506941658960408'''
    '''07198403850962455444362981230987879927244284909188'''
    '''84580156166097919133875499200524063689912560717606'''
    '''05886116467109405077541002256983155200055935729725'''
    '''71636269561882670428252483600823257530420752963450'''
)


def     a   (    __a     )						->			int:



					'''simple docstring'''






					UpperCamelCase__     :Tuple							      =				1
					for digit in s:
										product *= int(__a     )
					return product


def     a   (    __a = N     )						->			int:



					'''simple docstring'''






					UpperCamelCase__     :Tuple							      =				-sys.maxsize - 1
					UpperCamelCase__     :Dict							      =				n[:13]
					UpperCamelCase__     :Dict							      =				13
					while cur_index < len(__a     ) - 13:
										if int(n[cur_index]     ) >= int(substr[0]     ):
															UpperCamelCase__     :Dict							      =				substr[1:] + n[cur_index]
															cur_index += 1
										else:
															UpperCamelCase__     :List[str]							      =				max(__a				,      str_eval(__a     )     )
															UpperCamelCase__     :Union[str, Any]							      =				n[cur_index : cur_index + 13]
															cur_index += 13
					return largest_product


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