




"""simple docstring"""






from __future__ import annotations

import copy
import inspect
import json
import math
import os
import tempfile
import unittest
from importlib import import_module

import numpy as np

from transformers import ViTMAEConfig
from transformers.file_utils import cached_property, is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, require_vision, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers import TFViTMAEForPreTraining, TFViTMAEModel


if is_vision_available():
			from PIL import Image

			from transformers import ViTImageProcessor






class lowerCAmelCase__      :






			'''simple docstring'''



			def __init__(    self    , lowercase    , lowercase=13    , lowercase=30    , lowercase=2    , lowercase=3    , lowercase=True    , lowercase=True    , lowercase=32    , lowercase=2    , lowercase=4    , lowercase=37    , lowercase="gelu"    , lowercase=0.1    , lowercase=0.1    , lowercase=10    , lowercase=0.02    , lowercase=3    , lowercase=0.6    , lowercase=None    , ):
							_lowerCamelCase	:     str       =       parent
							_lowerCamelCase	:     List[str]       =       batch_size
							_lowerCamelCase	:     Optional[int]       =       image_size
							_lowerCamelCase	:     Union[str, Any]       =       patch_size
							_lowerCamelCase	:     Optional[Any]       =       num_channels
							_lowerCamelCase	:     Union[str, Any]       =       is_training
							_lowerCamelCase	:     Tuple       =       use_labels
							_lowerCamelCase	:     List[str]       =       hidden_size
							_lowerCamelCase	:     List[str]       =       num_hidden_layers
							_lowerCamelCase	:     List[Any]       =       num_attention_heads
							_lowerCamelCase	:     Optional[int]       =       intermediate_size
							_lowerCamelCase	:     Optional[Any]       =       hidden_act
							_lowerCamelCase	:     Dict       =       hidden_dropout_prob
							_lowerCamelCase	:     int       =       attention_probs_dropout_prob
							_lowerCamelCase	:     Optional[int]       =       type_sequence_label_size
							_lowerCamelCase	:     Optional[Any]       =       initializer_range
							_lowerCamelCase	:     str       =       mask_ratio
							_lowerCamelCase	:     List[Any]       =       scope

							# in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
							# (we add 1 for the [CLS] token)
							_lowerCamelCase	:     int       =       (image_size // patch_size) ** 2
							_lowerCamelCase	:     List[Any]       =       int(math.ceil((1 - mask_ratio) * (num_patches + 1)    )    )
			def    A_       (    self    ):
							_lowerCamelCase	:     int       =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

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

							_lowerCamelCase	:     Union[str, Any]       =       self.get_config()

							return config, pixel_values, labels
			def    A_       (    self    ):
							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    , decoder_hidden_size=self.hidden_size    , decoder_num_hidden_layers=self.num_hidden_layers    , decoder_num_attention_heads=self.num_attention_heads    , decoder_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=lowercase    , initializer_range=self.initializer_range    , mask_ratio=self.mask_ratio    , )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     str       =       TFViTMAEModel(config=lowercase    )
							_lowerCamelCase	:     List[str]       =       model(lowercase    , training=lowercase    )
							self.parent.assertEqual(result.last_hidden_state.shape    , (self.batch_size, self.seq_length, self.hidden_size)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     Dict       =       TFViTMAEForPreTraining(lowercase    )
							_lowerCamelCase	:     Any       =       model(lowercase    , training=lowercase    )
							# expected sequence length = num_patches
							_lowerCamelCase	:     Dict       =       (self.image_size // self.patch_size) ** 2
							_lowerCamelCase	:     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
							_lowerCamelCase	:     Tuple       =       1
							_lowerCamelCase	:     List[str]       =       TFViTMAEForPreTraining(lowercase    )

							_lowerCamelCase	:     Optional[int]       =       floats_tensor([self.batch_size, 1, self.image_size, self.image_size]    )
							_lowerCamelCase	:     List[Any]       =       model(lowercase    , training=lowercase    )
							_lowerCamelCase	:     Optional[int]       =       self.patch_size**2
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, num_patches, expected_num_channels)    )






			def    A_       (    self    ):
							_lowerCamelCase	:     Tuple       =       self.prepare_config_and_inputs()
							((_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase))	:     Any       =       config_and_inputs
							_lowerCamelCase	:     Optional[Any]       =       {'pixel_values': pixel_values}
							return config, inputs_dict






@require_tf
class lowerCAmelCase__      (	UpperCAmelCase__,      UpperCAmelCase__,      unittest.TestCase		):






			'''simple docstring'''



			lowerCamelCase__ =     (TFViTMAEModel, TFViTMAEForPreTraining) if is_tf_available() else ()
			lowerCamelCase__ =     {"feature-extraction": TFViTMAEModel} if is_tf_available() else {}

			lowerCamelCase__ =     False
			lowerCamelCase__ =     False
			lowerCamelCase__ =     False
			lowerCamelCase__ =     False
			def    A_       (    self    ):
							_lowerCamelCase	:     Union[str, Any]       =       TFViTMAEModelTester(self    )
							_lowerCamelCase	:     Optional[int]       =       ConfigTester(self    , config_class=lowercase    , has_text_modality=lowercase    , hidden_size=37    )
			def    A_       (    self    ):
							self.config_tester.run_common_tests()
			@unittest.skip(reason='ViTMAE does not use inputs_embeds'    )
			def    A_       (    self    ):
							pass
			def    A_       (    self    ):
							_lowerCamelCase,					_lowerCamelCase	:     Tuple       =       self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
											_lowerCamelCase	:     Any       =       model_class(lowercase    )
											self.assertIsInstance(model.get_input_embeddings()    , (tf.keras.layers.Layer)    )
											_lowerCamelCase	:     Optional[int]       =       model.get_output_embeddings()
											self.assertTrue(x is None or isinstance(lowercase    , tf.keras.layers.Layer    )    )
			def    A_       (    self    ):
							_lowerCamelCase,					_lowerCamelCase	:     List[str]       =       self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
											_lowerCamelCase	:     int       =       model_class(lowercase    )
											_lowerCamelCase	:     Optional[Any]       =       inspect.signature(model.call    )
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											_lowerCamelCase	:     Tuple       =       [*signature.parameters.keys()]

											_lowerCamelCase	:     Optional[Any]       =       ['pixel_values']
											self.assertListEqual(arg_names[:1]    , lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[Any]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Union[str, Any]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*lowercase    )
			def    A_       (    self    ):
							np.random.seed(2    )

							_lowerCamelCase,					_lowerCamelCase	:     Tuple       =       self.model_tester.prepare_config_and_inputs_for_common()

							_lowerCamelCase	:     Optional[Any]       =       int((config.image_size // config.patch_size) ** 2    )
							_lowerCamelCase	:     Optional[Any]       =       np.random.uniform(size=(self.model_tester.batch_size, num_patches)    )

							for model_class in self.all_model_classes:
											_lowerCamelCase	:     str       =       model_class(lowercase    )
											_lowerCamelCase	:     str       =       self._prepare_for_class(lowercase    , lowercase    )

											_lowerCamelCase	:     Dict       =       model(lowercase    , noise=lowercase    )

											_lowerCamelCase	:     int       =       copy.deepcopy(self._prepare_for_class(lowercase    , lowercase    )    )
											_lowerCamelCase	:     str       =       model(**lowercase    , noise=lowercase    )
											_lowerCamelCase	:     List[str]       =       outputs_dict[0].numpy()
											_lowerCamelCase	:     Optional[Any]       =       outputs_keywords[0].numpy()

											self.assertLess(np.sum(np.abs(output_dict - output_keywords    )    )    , 1E-6    )
			def    A_       (    self    ):
							np.random.seed(2    )

							_lowerCamelCase,					_lowerCamelCase	:     Any       =       self.model_tester.prepare_config_and_inputs_for_common()

							_lowerCamelCase	:     Dict       =       int((config.image_size // config.patch_size) ** 2    )
							_lowerCamelCase	:     Dict       =       np.random.uniform(size=(self.model_tester.batch_size, num_patches)    )

							def prepare_numpy_arrays(lowercase    ):
											_lowerCamelCase	:     str       =       {}
											for k, v in inputs_dict.items():
															if tf.is_tensor(lowercase    ):
																			_lowerCamelCase	:     int       =       v.numpy()
															else:
																			_lowerCamelCase	:     Optional[Any]       =       np.array(lowercase    )

											return inputs_np_dict

							for model_class in self.all_model_classes:
											_lowerCamelCase	:     str       =       model_class(lowercase    )

											_lowerCamelCase	:     Union[str, Any]       =       self._prepare_for_class(lowercase    , lowercase    )
											_lowerCamelCase	:     List[str]       =       prepare_numpy_arrays(lowercase    )

											_lowerCamelCase	:     int       =       model(lowercase    , noise=lowercase    )
											_lowerCamelCase	:     int       =       model(**lowercase    , noise=lowercase    )
											self.assert_outputs_same(lowercase    , lowercase    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    ):
							np.random.seed(2    )

							_lowerCamelCase	:     Any       =       int((tf_model.config.image_size // tf_model.config.patch_size) ** 2    )
							_lowerCamelCase	:     Optional[int]       =       np.random.uniform(size=(self.model_tester.batch_size, num_patches)    )
							_lowerCamelCase	:     Any       =       tf.constant(lowercase    )

							# Add `noise` argument.
							# PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
							_lowerCamelCase	:     Dict       =       tf_noise

							super().check_pt_tf_models(lowercase    , lowercase    , lowercase    )
			def    A_       (    self    ):
							np.random.seed(2    )

							_lowerCamelCase,					_lowerCamelCase	:     List[Any]       =       self.model_tester.prepare_config_and_inputs_for_common()

							_lowerCamelCase	:     Optional[Any]       =       {
							    module_member
							    for model_class in self.all_model_classes
							    for module in (import_module(model_class.__module__    ),)
							    for module_member_name in dir(lowercase    )
							    if module_member_name.endswith('MainLayer'    )
							    # This condition is required, since `modeling_tf_clip.py` has 3 classes whose names end with `MainLayer`.
							    and module_member_name[: -len('MainLayer'    )] == model_class.__name__[: -len('Model'    )]
							    for module_member in (getattr(lowercase    , lowercase    ),)
							    if isinstance(lowercase    , lowercase    )
							    and tf.keras.layers.Layer in module_member.__bases__
							    and getattr(lowercase    , '_keras_serializable'    , lowercase    )
							}

							_lowerCamelCase	:     Optional[int]       =       int((config.image_size // config.patch_size) ** 2    )
							_lowerCamelCase	:     Optional[int]       =       np.random.uniform(size=(self.model_tester.batch_size, num_patches)    )
							_lowerCamelCase	:     Optional[Any]       =       tf.convert_to_tensor(lowercase    )
							inputs_dict.update({'noise': noise}    )

							for main_layer_class in tf_main_layer_classes:
											_lowerCamelCase	:     List[str]       =       main_layer_class(lowercase    )

											_lowerCamelCase	:     List[Any]       =       {
											    name: tf.keras.Input(tensor.shape[1:]    , dtype=tensor.dtype    ) for name, tensor in inputs_dict.items()
											}

											_lowerCamelCase	:     Optional[Any]       =       tf.keras.Model(lowercase    , outputs=main_layer(lowercase    )    )
											_lowerCamelCase	:     Union[str, Any]       =       model(lowercase    )

											with tempfile.TemporaryDirectory() as tmpdirname:
															_lowerCamelCase	:     Any       =       os.path.join(lowercase    , 'keras_model.h5'    )
															model.save(lowercase    )
															_lowerCamelCase	:     Any       =       tf.keras.models.load_model(
															    lowercase    , custom_objects={main_layer_class.__name__: main_layer_class}    )
															assert isinstance(lowercase    , tf.keras.Model    )
															_lowerCamelCase	:     List[str]       =       model(lowercase    )
															self.assert_outputs_same(lowercase    , lowercase    )
			@slow
			def    A_       (    self    ):
							np.random.seed(2    )

							_lowerCamelCase,					_lowerCamelCase	:     List[str]       =       self.model_tester.prepare_config_and_inputs_for_common()

							_lowerCamelCase	:     Optional[Any]       =       int((config.image_size // config.patch_size) ** 2    )
							_lowerCamelCase	:     Dict       =       np.random.uniform(size=(self.model_tester.batch_size, num_patches)    )

							for model_class in self.all_model_classes:
											_lowerCamelCase	:     int       =       model_class(lowercase    )
											_lowerCamelCase	:     Optional[Any]       =       self._prepare_for_class(lowercase    , lowercase    )
											_lowerCamelCase	:     Union[str, Any]       =       model(lowercase    , noise=lowercase    )

											if model_class.__name__ == "TFViTMAEModel":
															_lowerCamelCase	:     Optional[int]       =       outputs.last_hidden_state.numpy()
															_lowerCamelCase	:     Any       =       0
											else:
															_lowerCamelCase	:     int       =       outputs.logits.numpy()
															_lowerCamelCase	:     Optional[Any]       =       0

											with tempfile.TemporaryDirectory() as tmpdirname:
															model.save_pretrained(lowercase    , saved_model=lowercase    )
															_lowerCamelCase	:     str       =       model_class.from_pretrained(lowercase    )
															_lowerCamelCase	:     Union[str, Any]       =       model(lowercase    , noise=lowercase    )

															if model_class.__name__ == "TFViTMAEModel":
																			_lowerCamelCase	:     Dict       =       after_outputs['last_hidden_state'].numpy()
																			_lowerCamelCase	:     str       =       0
															else:
																			_lowerCamelCase	:     List[Any]       =       after_outputs['logits'].numpy()
																			_lowerCamelCase	:     List[Any]       =       0

															_lowerCamelCase	:     int       =       np.amax(np.abs(out_a - out_a    )    )
															self.assertLessEqual(lowercase    , 1E-5    )
			def    A_       (    self    ):
							np.random.seed(2    )

							_lowerCamelCase,					_lowerCamelCase	:     Optional[Any]       =       self.model_tester.prepare_config_and_inputs_for_common()

							_lowerCamelCase	:     Optional[Any]       =       int((config.image_size // config.patch_size) ** 2    )
							_lowerCamelCase	:     Dict       =       np.random.uniform(size=(self.model_tester.batch_size, num_patches)    )

							for model_class in self.all_model_classes:
											_lowerCamelCase	:     List[str]       =       model_class(lowercase    )
											_lowerCamelCase	:     Tuple       =       self._prepare_for_class(lowercase    , lowercase    )

											_lowerCamelCase	:     List[str]       =       model(lowercase    , noise=lowercase    )
											_lowerCamelCase	:     Dict       =       model.get_config()
											# make sure that returned config is jsonifiable, which is required by keras
											json.dumps(lowercase    )
											_lowerCamelCase	:     Tuple       =       model_class.from_config(model.get_config()    )
											# make sure it also accepts a normal config
											_lowerCamelCase	:     Optional[int]       =       model_class.from_config(model.config    )
											_lowerCamelCase	:     str       =       new_model(lowercase    )  # Build model
											new_model.set_weights(model.get_weights()    )
											_lowerCamelCase	:     Optional[int]       =       new_model(lowercase    , noise=lowercase    )

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






			@slow
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[Any]       =       TFViTMAEModel.from_pretrained('google/vit-base-patch16-224'    )
							self.assertIsNotNone(lowercase    )







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






@require_tf
@require_vision
class lowerCAmelCase__      (	unittest.TestCase		):






			'''simple docstring'''



			@cached_property
			def    A_       (    self    ):
							return ViTImageProcessor.from_pretrained('facebook/vit-mae-base'    ) if is_vision_available() else None






			@slow
			def    A_       (    self    ):
							np.random.seed(2    )

							_lowerCamelCase	:     List[str]       =       TFViTMAEForPreTraining.from_pretrained('facebook/vit-mae-base'    )

							_lowerCamelCase	:     Any       =       self.default_image_processor
							_lowerCamelCase	:     List[str]       =       prepare_img()
							_lowerCamelCase	:     List[str]       =       image_processor(images=lowercase    , return_tensors='tf'    )

							# 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)
							_lowerCamelCase	:     str       =       ViTMAEConfig()
							_lowerCamelCase	:     List[Any]       =       int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2    )
							_lowerCamelCase	:     List[str]       =       np.random.uniform(size=(1, num_patches)    )

							# forward pass
							_lowerCamelCase	:     List[str]       =       model(**lowercase    , noise=lowercase    )

							# verify the logits
							_lowerCamelCase	:     List[Any]       =       tf.convert_to_tensor([1, 196, 768]    )
							self.assertEqual(outputs.logits.shape    , lowercase    )

							_lowerCamelCase	:     List[str]       =       tf.convert_to_tensor(
							    [[-0.05_48, -1.70_23, -0.93_25], [0.37_21, -0.56_70, -0.22_33], [0.82_35, -1.38_78, -0.35_24]]    )

							tf.debugging.assert_near(outputs.logits[0, :3, :3]    , lowercase    , atol=1E-4    )
'''simple docstring'''




def __lowerCAmelCase					(				)      ->       Optional[Any]:
    __lowerCamelCase            =    0
    for i in range(1							,    10_01							):
        total += i**i
    return str(UpperCamelCase__							)[-10:]


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