






from __future__ import annotations

import inspect
import unittest

from transformers import MobileViTConfig
from transformers.file_utils import is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, 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 numpy as np
				import tensorflow as tf

				from transformers import TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation, TFMobileViTModel
				from transformers.models.mobilevit.modeling_tf_mobilevit import TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import MobileViTImageProcessor







class 				lowerCamelCase_     (	UpperCamelCase_     ):
							def  SCREAMING_SNAKE_CASE_ (						self		:					Optional[Any]					):





								'''simple docstring'''



								a		=			self.config_class(**self.inputs_dict					)
								self.parent.assertTrue(hasattr(__SCREAMING_SNAKE_CASE							,'''hidden_sizes'''					)					)
								self.parent.assertTrue(hasattr(__SCREAMING_SNAKE_CASE							,'''neck_hidden_sizes'''					)					)
								self.parent.assertTrue(hasattr(__SCREAMING_SNAKE_CASE							,'''num_attention_heads'''					)					)







class 				lowerCamelCase_     :
							def __init__(						self		:					Union[str, Any]							,__lowerCamelCase		:					List[str]							,__lowerCamelCase		:					Optional[Any]=13							,__lowerCamelCase		:					List[Any]=32							,__lowerCamelCase		:					Dict=2							,__lowerCamelCase		:					Optional[Any]=3							,__lowerCamelCase		:					int=6_40							,__lowerCamelCase		:					Tuple=4							,__lowerCamelCase		:					Tuple="silu"							,__lowerCamelCase		:					int=3							,__lowerCamelCase		:					List[str]=32							,__lowerCamelCase		:					Union[str, Any]=0.1							,__lowerCamelCase		:					str=0.1							,__lowerCamelCase		:					Optional[Any]=0.1							,__lowerCamelCase		:					Optional[int]=0.02							,__lowerCamelCase		:					Any=True							,__lowerCamelCase		:					Tuple=True							,__lowerCamelCase		:					Dict=10							,__lowerCamelCase		:					List[str]=None							,):





								'''simple docstring'''



								a		=			parent
								a		=			batch_size
								a		=			image_size
								a		=			patch_size
								a		=			num_channels
								a		=			last_hidden_size
								a		=			num_attention_heads
								a		=			hidden_act
								a		=			conv_kernel_size
								a		=			output_stride
								a		=			hidden_dropout_prob
								a		=			attention_probs_dropout_prob
								a		=			classifier_dropout_prob
								a		=			use_labels
								a		=			is_training
								a		=			num_labels
								a		=			initializer_range
								a		=			scope
							def  SCREAMING_SNAKE_CASE_ (						self		:					Dict					):





								'''simple docstring'''



								a		=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

								a		=			None
								a		=			None
								if self.use_labels:
									a		=			ids_tensor([self.batch_size]							,self.num_labels					)
									a		=			ids_tensor([self.batch_size, self.image_size, self.image_size]							,self.num_labels					)

								a		=			self.get_config()

								return config, pixel_values, labels, pixel_labels
							def  SCREAMING_SNAKE_CASE_ (						self		:					Optional[int]					):





								'''simple docstring'''



								return MobileViTConfig(
								    image_size=self.image_size							,patch_size=self.patch_size							,num_channels=self.num_channels							,num_attention_heads=self.num_attention_heads							,hidden_act=self.hidden_act							,conv_kernel_size=self.conv_kernel_size							,output_stride=self.output_stride							,hidden_dropout_prob=self.hidden_dropout_prob							,attention_probs_dropout_prob=self.attention_probs_dropout_prob							,classifier_dropout_prob=self.classifier_dropout_prob							,initializer_range=self.initializer_range							,)
							def  SCREAMING_SNAKE_CASE_ (						self		:					Optional[Any]							,__lowerCamelCase		:					Union[str, Any]							,__lowerCamelCase		:					Optional[int]							,__lowerCamelCase		:					str							,__lowerCamelCase		:					List[str]					):





								'''simple docstring'''



								a		=			TFMobileViTModel(config=__SCREAMING_SNAKE_CASE					)
								a		=			model(__SCREAMING_SNAKE_CASE							,training=__SCREAMING_SNAKE_CASE					)
								a		=			a		=			self.image_size // self.output_stride
								self.parent.assertEqual(
								    result.last_hidden_state.shape							,(self.batch_size, self.last_hidden_size, expected_height, expected_width)					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					str							,__lowerCamelCase		:					List[str]							,__lowerCamelCase		:					Union[str, Any]							,__lowerCamelCase		:					Any							,__lowerCamelCase		:					List[Any]					):





								'''simple docstring'''



								a		=			self.num_labels
								a		=			TFMobileViTForImageClassification(__SCREAMING_SNAKE_CASE					)
								a		=			model(__SCREAMING_SNAKE_CASE							,labels=__SCREAMING_SNAKE_CASE							,training=__SCREAMING_SNAKE_CASE					)
								self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_labels)					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					Dict							,__lowerCamelCase		:					Union[str, Any]							,__lowerCamelCase		:					Optional[int]							,__lowerCamelCase		:					str							,__lowerCamelCase		:					Dict					):





								'''simple docstring'''



								a		=			self.num_labels
								a		=			TFMobileViTForSemanticSegmentation(__SCREAMING_SNAKE_CASE					)
								a		=			a		=			self.image_size // self.output_stride

								a		=			model(__SCREAMING_SNAKE_CASE							,training=__SCREAMING_SNAKE_CASE					)
								self.parent.assertEqual(
								    result.logits.shape							,(self.batch_size, self.num_labels, expected_height, expected_width)					)

								a		=			model(__SCREAMING_SNAKE_CASE							,labels=__SCREAMING_SNAKE_CASE							,training=__SCREAMING_SNAKE_CASE					)
								self.parent.assertEqual(
								    result.logits.shape							,(self.batch_size, self.num_labels, expected_height, expected_width)					)




							def  SCREAMING_SNAKE_CASE_ (						self		:					Union[str, Any]					):





								'''simple docstring'''



								a		=			self.prepare_config_and_inputs()
								a	, a	, a	, a		=			config_and_inputs
								a		=			{'''pixel_values''': pixel_values}
								return config, inputs_dict







@require_tf
class 				lowerCamelCase_     (	UpperCamelCase_ ,						UpperCamelCase_ ,						unittest.TestCase     ):
							SCREAMING_SNAKE_CASE_						     =			(
							    (TFMobileViTModel, TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation)
							    if is_tf_available()
							    else ()
							)
							SCREAMING_SNAKE_CASE_						     =			(
							    {"""feature-extraction""": TFMobileViTModel, """image-classification""": TFMobileViTForImageClassification}
							    if is_tf_available()
							    else {}
							)

							SCREAMING_SNAKE_CASE_						     =			False
							SCREAMING_SNAKE_CASE_						     =			False
							SCREAMING_SNAKE_CASE_						     =			False
							SCREAMING_SNAKE_CASE_						     =			False
							SCREAMING_SNAKE_CASE_						     =			False
							def  SCREAMING_SNAKE_CASE_ (						self		:					Union[str, Any]					):





								'''simple docstring'''



								a		=			TFMobileViTModelTester(self					)
								a		=			TFMobileViTConfigTester(self							,config_class=__SCREAMING_SNAKE_CASE							,has_text_modality=__SCREAMING_SNAKE_CASE					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					int					):





								'''simple docstring'''



								self.config_tester.run_common_tests()
							@unittest.skip(reason='''MobileViT does not use inputs_embeds'''					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					List[str]					):





								'''simple docstring'''



								pass
							@unittest.skip(reason='''MobileViT does not support input and output embeddings'''					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					Dict					):





								'''simple docstring'''



								pass
							@unittest.skip(reason='''MobileViT does not output attentions'''					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					Dict					):





								'''simple docstring'''



								pass
							def  SCREAMING_SNAKE_CASE_ (						self		:					str					):





								'''simple docstring'''



								a	, a		=			self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									a		=			model_class(__SCREAMING_SNAKE_CASE					)
									a		=			inspect.signature(model.call					)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									a		=			[*signature.parameters.keys()]

									a		=			['''pixel_values''']
									self.assertListEqual(arg_names[:1]							,__SCREAMING_SNAKE_CASE					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					Dict					):





								'''simple docstring'''



								a		=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					str					):





								'''simple docstring'''



								def check_hidden_states_output(__lowerCamelCase		:					Dict							,__lowerCamelCase		:					Union[str, Any]							,__lowerCamelCase		:					Optional[int]					):
									a		=			model_class(__SCREAMING_SNAKE_CASE					)

									a		=			model(**self._prepare_for_class(__SCREAMING_SNAKE_CASE							,__SCREAMING_SNAKE_CASE					)					)

									a		=			outputs.hidden_states

									a		=			5
									self.assertEqual(len(__SCREAMING_SNAKE_CASE					)							,__SCREAMING_SNAKE_CASE					)

									# MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
									# with the width and height being successively divided by 2.
									a		=			2
									for i in range(len(__SCREAMING_SNAKE_CASE					)					):
										self.assertListEqual(
										    list(hidden_states[i].shape[-2:]					)							,[self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]							,)
										divisor *= 2

									self.assertEqual(self.model_tester.output_stride							,divisor // 2					)

								a	, a		=			self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									a		=			True
									check_hidden_states_output(__SCREAMING_SNAKE_CASE							,__SCREAMING_SNAKE_CASE							,__SCREAMING_SNAKE_CASE					)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									a		=			True

									check_hidden_states_output(__SCREAMING_SNAKE_CASE							,__SCREAMING_SNAKE_CASE							,__SCREAMING_SNAKE_CASE					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					Union[str, Any]					):





								'''simple docstring'''



								a		=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*__SCREAMING_SNAKE_CASE					)
							def  SCREAMING_SNAKE_CASE_ (						self		:					Optional[int]					):





								'''simple docstring'''



								a		=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_semantic_segmentation(*__SCREAMING_SNAKE_CASE					)
							@unittest.skipIf(
							    not is_tf_available() or len(tf.config.list_physical_devices('''GPU'''					)					) == 0							,reason='''TF does not support backprop for grouped convolutions on CPU.'''							,)
							def  SCREAMING_SNAKE_CASE_ (						self		:					str					):





								'''simple docstring'''



								super().test_dataset_conversion()
							def  SCREAMING_SNAKE_CASE_ (						self		:					Tuple							,__lowerCamelCase		:					Any							,__lowerCamelCase		:					List[str]							,__lowerCamelCase		:					List[str]=2e-1							,__lowerCamelCase		:					Any=2e-1					):





								'''simple docstring'''



								self.assertTrue(np.allclose(__SCREAMING_SNAKE_CASE							,__SCREAMING_SNAKE_CASE							,atol=__SCREAMING_SNAKE_CASE							,rtol=__SCREAMING_SNAKE_CASE					)					)
							@unittest.skipIf(
							    not is_tf_available() or len(tf.config.list_physical_devices('''GPU'''					)					) == 0							,reason='''TF does not support backprop for grouped convolutions on CPU.'''							,)
							@slow
							def  SCREAMING_SNAKE_CASE_ (						self		:					Optional[int]					):





								'''simple docstring'''



								a	, a		=			self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									# Since `TFMobileViTModel` cannot operate with the default `fit()` method.
									if model_class.__name__ != "TFMobileViTModel":
										a		=			model_class(__SCREAMING_SNAKE_CASE					)
										if getattr(__SCREAMING_SNAKE_CASE							,'''hf_compute_loss'''							,__SCREAMING_SNAKE_CASE					):
											super().test_keras_fit()
							def  SCREAMING_SNAKE_CASE_ (						self		:					str					):





								'''simple docstring'''



								a	, a		=			self.model_tester.prepare_config_and_inputs_for_common()
								for model_class in self.all_model_classes:
									# set an ignore index to correctly test the masked loss used in
									# `TFMobileViTForSemanticSegmentation`.
									if model_class.__name__ != "TFMobileViTForSemanticSegmentation":
										a		=			5

									a		=			model_class(__SCREAMING_SNAKE_CASE					)
									if getattr(__SCREAMING_SNAKE_CASE							,'''hf_compute_loss'''							,__SCREAMING_SNAKE_CASE					):
										# The number of elements in the loss should be the same as the number of elements in the label
										a		=			self._prepare_for_class(inputs_dict.copy()							,__SCREAMING_SNAKE_CASE							,return_labels=__SCREAMING_SNAKE_CASE					)
										a		=			prepared_for_class[
										    sorted(prepared_for_class.keys() - inputs_dict.keys()							,reverse=__SCREAMING_SNAKE_CASE					)[0]
										]
										a		=			added_label.shape.as_list()[:1]

										# Test that model correctly compute the loss with kwargs
										a		=			self._prepare_for_class(inputs_dict.copy()							,__SCREAMING_SNAKE_CASE							,return_labels=__SCREAMING_SNAKE_CASE					)
										a		=			{'''input_ids''', '''pixel_values''', '''input_features'''}
										a		=			possible_input_names.intersection(set(__SCREAMING_SNAKE_CASE					)					).pop()
										a		=			prepared_for_class.pop(__SCREAMING_SNAKE_CASE					)

										a		=			model(__SCREAMING_SNAKE_CASE							,**__SCREAMING_SNAKE_CASE					)[0]
										self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)

										# Test that model correctly compute the loss when we mask some positions
										a		=			self._prepare_for_class(inputs_dict.copy()							,__SCREAMING_SNAKE_CASE							,return_labels=__SCREAMING_SNAKE_CASE					)
										a		=			{'''input_ids''', '''pixel_values''', '''input_features'''}
										a		=			possible_input_names.intersection(set(__SCREAMING_SNAKE_CASE					)					).pop()
										a		=			prepared_for_class.pop(__SCREAMING_SNAKE_CASE					)
										if "labels" in prepared_for_class:
											a		=			prepared_for_class['''labels'''].numpy()
											if len(labels.shape					) > 1 and labels.shape[1] != 1:
												# labels[0] = -100
												a		=			tf.convert_to_tensor(__SCREAMING_SNAKE_CASE					)
												a		=			model(__SCREAMING_SNAKE_CASE							,**__SCREAMING_SNAKE_CASE					)[0]
												self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)
												self.assertTrue(not np.any(np.isnan(loss.numpy()					)					)					)

                # Test that model correctly compute the loss with a dict
										a		=			self._prepare_for_class(inputs_dict.copy()							,__SCREAMING_SNAKE_CASE							,return_labels=__SCREAMING_SNAKE_CASE					)
										a		=			model(__SCREAMING_SNAKE_CASE					)[0]
										self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)

										# Test that model correctly compute the loss with a tuple
										a		=			self._prepare_for_class(inputs_dict.copy()							,__SCREAMING_SNAKE_CASE							,return_labels=__SCREAMING_SNAKE_CASE					)

										# Get keys that were added with the _prepare_for_class function
										a		=			prepared_for_class.keys() - inputs_dict.keys()
										a		=			inspect.signature(model.call					).parameters
										a		=			list(signature.keys()					)

										# Create a dictionary holding the location of the tensors in the tuple
										a		=			{0: input_name}
										for label_key in label_keys:
											a		=			signature_names.index(__SCREAMING_SNAKE_CASE					)
											a		=			label_key
										a		=			sorted(tuple_index_mapping.items()					)
										# Initialize a list with their default values, update the values and convert to a tuple
										a		=			[]

										for name in signature_names:
											if name != "kwargs":
												list_input.append(signature[name].default					)

										for index, value in sorted_tuple_index_mapping:
											a		=			prepared_for_class[value]

										a		=			tuple(__SCREAMING_SNAKE_CASE					)

										# Send to model
										a		=			model(tuple_input[:-1]					)[0]

										self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]					)




							@slow
							def  SCREAMING_SNAKE_CASE_ (						self		:					Union[str, Any]					):





								'''simple docstring'''



								for model_name in TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a		=			TFMobileViTModel.from_pretrained(__SCREAMING_SNAKE_CASE					)
									self.assertIsNotNone(__SCREAMING_SNAKE_CASE					)





def   SCREAMING_SNAKE_CASE__						(   )   ->  List[str]:


	"""simple docstring"""



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







@require_tf
class 				lowerCamelCase_     (	unittest.TestCase     ):
							@slow
							def  SCREAMING_SNAKE_CASE_ (						self		:					int					):





								'''simple docstring'''



								a		=			TFMobileViTForImageClassification.from_pretrained('''apple/mobilevit-xx-small'''					)

								a		=			MobileViTImageProcessor.from_pretrained('''apple/mobilevit-xx-small'''					)
								a		=			prepare_img()
								a		=			image_processor(images=__SCREAMING_SNAKE_CASE							,return_tensors='''tf'''					)

								# forward pass
								a		=			model(**__SCREAMING_SNAKE_CASE							,training=__SCREAMING_SNAKE_CASE					)

								# verify the logits
								a		=			tf.TensorShape((1, 10_00)					)
								self.assertEqual(outputs.logits.shape							,__SCREAMING_SNAKE_CASE					)

								a		=			tf.constant([-1.9_364, -1.2_327, -0.4_653]					)

								tf.debugging.assert_near(outputs.logits[0, :3]							,__SCREAMING_SNAKE_CASE							,atol=1e-4							,rtol=1e-04					)




							@slow
							def  SCREAMING_SNAKE_CASE_ (						self		:					Tuple					):





								'''simple docstring'''



								a		=			TFMobileViTForSemanticSegmentation.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''					)

								a		=			MobileViTImageProcessor.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''					)

								a		=			prepare_img()
								a		=			image_processor(images=__SCREAMING_SNAKE_CASE							,return_tensors='''tf'''					)

								# forward pass
								a		=			model(inputs.pixel_values							,training=__SCREAMING_SNAKE_CASE					)
								a		=			outputs.logits

								# verify the logits
								a		=			tf.TensorShape((1, 21, 32, 32)					)
								self.assertEqual(logits.shape							,__SCREAMING_SNAKE_CASE					)

								a		=			tf.constant(
								    [
								        [[6.9_713, 6.9_786, 7.2_422], [7.2_893, 7.2_825, 7.4_446], [7.6_580, 7.8_797, 7.9_420]],
								        [[-10.68_69, -10.32_50, -10.34_71], [-10.42_28, -9.9_868, -9.7_132], [-11.04_05, -11.02_21, -10.73_18]],
								        [[-3.3_089, -2.8_539, -2.6_740], [-3.2_706, -2.5_621, -2.5_108], [-3.2_534, -2.6_615, -2.6_651]],
								    ]					)

								tf.debugging.assert_near(logits[0, :3, :3, :3]							,__SCREAMING_SNAKE_CASE							,rtol=1e-4							,atol=1e-4					)













UpperCamelCase__						:      Dict								=					10**8





def   SCREAMING_SNAKE_CASE__						(   snake_case_  )   ->  bool:


	"""simple docstring"""



	if n % 1_0 == 0:
		return False
	a		=			str(snake_case_  )
	return s == s[::-1]





def   SCREAMING_SNAKE_CASE__						(   )   ->  int:


	"""simple docstring"""



	a		=			set()
	a		=			1
	a		=			5
	while sum_squares < LIMIT:
		a		=			first_square + 1
		while sum_squares < LIMIT:
			if is_palindrome(snake_case_  ):
				answer.add(snake_case_  )
			last_square += 1
			sum_squares += last_square**2
		first_square += 1
		a		=			first_square**2 + (first_square + 1) ** 2

	return sum(snake_case_  )


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





