



'''simple docstring'''







import inspect
import unittest

from transformers import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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 transformers import MODEL_MAPPING, PoolFormerConfig, PoolFormerForImageClassification, PoolFormerModel
		from transformers.models.poolformer.modeling_poolformer import POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import PoolFormerImageProcessor

class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  str					)     ->			Union[str, Any]:




								'''simple docstring'''





								lowerCAmelCase__  =   self.config_class(**self.inputs_dict					)
								self.parent.assertTrue(hasattr(_lowerCAmelCase   ,		"""hidden_sizes"""					)					)
								self.parent.assertTrue(hasattr(_lowerCAmelCase   ,		"""num_encoder_blocks"""					)					)





class      lowerCamelCase__     :






	'''simple docstring'''

	def __init__(  self		:  int   ,		__A		:  Union[str, Any]   ,		__A		:  Any=13   ,		__A		:  int=64   ,		__A		:  Union[str, Any]=3   ,		__A		:  List[str]=4   ,		__A		:  int=[2, 2, 2, 2]   ,		__A		:  Union[str, Any]=[8, 4, 2, 1]   ,		__A		:  Dict=[16, 32, 64, 128]   ,		__A		:  List[Any]=[1, 4, 8, 16]   ,		__A		:  List[str]=False   ,		__A		:  Optional[Any]=True   ,		__A		:  str="gelu"   ,		__A		:  List[Any]=0.1   ,		__A		:  Optional[int]=0.0_2   ,		__A		:  str=3   ,		__A		:  Union[str, Any]=None   ,		)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  =   parent
								lowerCAmelCase__  =   batch_size
								lowerCAmelCase__  =   image_size
								lowerCAmelCase__  =   num_channels
								lowerCAmelCase__  =   num_encoder_blocks
								lowerCAmelCase__  =   sr_ratios
								lowerCAmelCase__  =   depths
								lowerCAmelCase__  =   hidden_sizes
								lowerCAmelCase__  =   downsampling_rates
								lowerCAmelCase__  =   is_training
								lowerCAmelCase__  =   use_labels
								lowerCAmelCase__  =   hidden_act
								lowerCAmelCase__  =   hidden_dropout_prob
								lowerCAmelCase__  =   initializer_range
								lowerCAmelCase__  =   num_labels
								lowerCAmelCase__  =   scope




	def      lowercase__							(  self		:  Optional[Any]					)     ->			List[str]:




								'''simple docstring'''





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

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

								lowerCAmelCase__  =   PoolFormerConfig(
								    image_size=self.image_size   ,		num_channels=self.num_channels   ,		num_encoder_blocks=self.num_encoder_blocks   ,		depths=self.depths   ,		hidden_sizes=self.hidden_sizes   ,		hidden_act=self.hidden_act   ,		hidden_dropout_prob=self.hidden_dropout_prob   ,		initializer_range=self.initializer_range   ,		)

								return config, pixel_values, labels




	def      lowercase__							(  self		:  Tuple   ,		__A		:  str   ,		__A		:  int   ,		__A		:  Union[str, Any]					)     ->			Union[str, Any]:




								'''simple docstring'''





								lowerCAmelCase__  =   PoolFormerModel(config=_lowerCAmelCase					)
								model.to(_lowerCAmelCase					)
								model.eval()
								lowerCAmelCase__  =   model(_lowerCAmelCase					)
								lowerCAmelCase__  =   self.image_size // 3_2.0
								self.parent.assertEqual(
								    result.last_hidden_state.shape   ,		(self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)					)




	def      lowercase__							(  self		:  List[Any]					)     ->			Dict:




								'''simple docstring'''





								lowerCAmelCase__  =   self.prepare_config_and_inputs()
								lowerCAmelCase__  =   config_and_inputs
								lowerCAmelCase__  =   {"pixel_values": pixel_values}
								return config, inputs_dict





@require_torch
class      lowerCamelCase__     (     _A,     _A,     unittest.TestCase				):






	'''simple docstring'''

	A__		=	(PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else ()
	A__		=	(
	    {'''feature-extraction''': PoolFormerModel, '''image-classification''': PoolFormerForImageClassification}
	    if is_torch_available()
	    else {}
	)

	A__		=	False
	A__		=	False
	A__		=	False
	A__		=	False
	A__		=	False




	def      lowercase__							(  self		:  Any					)     ->			List[str]:




								'''simple docstring'''





								lowerCAmelCase__  =   PoolFormerModelTester(self					)
								lowerCAmelCase__  =   PoolFormerConfigTester(self   ,		config_class=_lowerCAmelCase					)




	def      lowercase__							(  self		:  List[Any]					)     ->			Tuple:




								'''simple docstring'''





								self.config_tester.run_common_tests()




	def      lowercase__							(  self		:  Dict					)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_lowerCAmelCase					)




	@unittest.skip("""PoolFormer does not use inputs_embeds"""					)
	def      lowercase__							(  self		:  Optional[int]					)     ->			List[str]:




								'''simple docstring'''





								pass




	@unittest.skip("""PoolFormer does not have get_input_embeddings method and get_output_embeddings methods"""					)
	def      lowercase__							(  self		:  int					)     ->			str:




								'''simple docstring'''





								pass




	def      lowercase__							(  self		:  List[str]					)     ->			Union[str, Any]:




								'''simple docstring'''





								def check_hidden_states_output(__A		:  Optional[Any]   ,		__A		:  int   ,		__A		:  Any					):
															lowerCAmelCase__  =   model_class(_lowerCAmelCase					)
															model.to(_lowerCAmelCase					)
															model.eval()

															with torch.no_grad():
																						lowerCAmelCase__  =   model(**self._prepare_for_class(_lowerCAmelCase   ,		_lowerCAmelCase					)					)

															lowerCAmelCase__  =   outputs.hidden_states

															lowerCAmelCase__  =   self.model_tester.num_encoder_blocks
															self.assertEqual(len(_lowerCAmelCase					)   ,		_lowerCAmelCase					)

															# verify the first hidden states (first block)
															self.assertListEqual(
															    list(hidden_states[0].shape[-3:]					)   ,		[
															        self.model_tester.hidden_sizes[0],
															        self.model_tester.image_size // 4,
															        self.model_tester.image_size // 4,
															    ]   ,		)

								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															lowerCAmelCase__  =   True
															check_hidden_states_output(_lowerCAmelCase   ,		_lowerCAmelCase   ,		_lowerCAmelCase					)

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

															check_hidden_states_output(_lowerCAmelCase   ,		_lowerCAmelCase   ,		_lowerCAmelCase					)




	def      lowercase__							(  self		:  Union[str, Any]					)     ->			Optional[int]:




								'''simple docstring'''





								if not self.model_tester.is_training:
															return

								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs_for_common()
								lowerCAmelCase__  =   True

								for model_class in self.all_model_classes:
															if model_class in get_values(_lowerCAmelCase					):
																						continue
															lowerCAmelCase__  =   model_class(_lowerCAmelCase					)
															model.to(_lowerCAmelCase					)
															model.train()
															lowerCAmelCase__  =   self._prepare_for_class(_lowerCAmelCase   ,		_lowerCAmelCase   ,		return_labels=_lowerCAmelCase					)
															lowerCAmelCase__  =   model(**_lowerCAmelCase					).loss
															loss.backward()




	def      lowercase__							(  self		:  Optional[Any]					)     ->			Tuple:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs_for_common()

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

															lowerCAmelCase__  =   ["pixel_values"]
															self.assertListEqual(arg_names[:1]   ,		_lowerCAmelCase					)




	@slow
	def      lowercase__							(  self		:  str					)     ->			List[Any]:




								'''simple docstring'''





								for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															lowerCAmelCase__  =   PoolFormerModel.from_pretrained(_lowerCAmelCase					)
															self.assertIsNotNone(_lowerCAmelCase					)





def 			_lowerCAmelCase(      ) ->							List[Any]:
							lowerCAmelCase__  =   Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""						)
							return image






@require_torch
class      lowerCamelCase__     (     unittest.TestCase				):






	'''simple docstring'''

	@slow
	def      lowercase__							(  self		:  List[str]					)     ->			Union[str, Any]:




								'''simple docstring'''





								lowerCAmelCase__  =   PoolFormerImageProcessor()
								lowerCAmelCase__  =   PoolFormerForImageClassification.from_pretrained("""sail/poolformer_s12"""					).to(_lowerCAmelCase					)

								lowerCAmelCase__  =   image_processor(images=prepare_img()   ,		return_tensors="""pt"""					).to(_lowerCAmelCase					)

								# forward pass
								with torch.no_grad():
															lowerCAmelCase__  =   model(**_lowerCAmelCase					)

								# verify the logits
								lowerCAmelCase__  =   torch.Size((1, 1000)					)
								self.assertEqual(outputs.logits.shape   ,		_lowerCAmelCase					)

								lowerCAmelCase__  =   torch.tensor([-0.6_1_1_3, 0.1_6_8_5, -0.0_4_9_2]					).to(_lowerCAmelCase					)
								self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,		_lowerCAmelCase   ,		atol=1E-4					)					)











import decimal



def    UpperCAmelCase__	(  ):
  lowercase     :int   						=    0
  lowercase     :str   						=    decimal.Context(prec=105 )
  for i in range(2,      100 ):
    lowercase     :int   						=    decimal.Decimal(lowerCamelCase )
    lowercase     :str   						=    number.sqrt(lowerCamelCase )
    if len(str(lowerCamelCase ) ) > 1:
      answer += int(str(lowerCamelCase )[0] )
      lowercase     :int   						=    str(lowerCamelCase )[2:101]
      answer += sum(int(lowerCamelCase ) for x in sqrt_number_str )
  return answer


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     print(f'''{solution() = }''')



