





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 SCREAMING_SNAKE_CASE_    (       snake_case_       ):






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







							"""simple docstring"""


							snake_case_		:      int           =						self.config_class(**self.inputs_dict						)
							self.parent.assertTrue(hasattr(_A		, 'hidden_sizes'						)						)
							self.parent.assertTrue(hasattr(_A		, 'num_encoder_blocks'						)						)
class SCREAMING_SNAKE_CASE_    :






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







							"""simple docstring"""


							snake_case_		:      Optional[Any]           =						parent
							snake_case_		:      List[Any]           =						batch_size
							snake_case_		:      Optional[int]           =						image_size
							snake_case_		:      Tuple           =						num_channels
							snake_case_		:      List[str]           =						num_encoder_blocks
							snake_case_		:      Any           =						sr_ratios
							snake_case_		:      Any           =						depths
							snake_case_		:      Union[str, Any]           =						hidden_sizes
							snake_case_		:      List[str]           =						downsampling_rates
							snake_case_		:      Dict           =						is_training
							snake_case_		:      Dict           =						use_labels
							snake_case_		:      List[str]           =						hidden_act
							snake_case_		:      List[Any]           =						hidden_dropout_prob
							snake_case_		:      Optional[int]           =						initializer_range
							snake_case_		:      Dict           =						num_labels
							snake_case_		:      List[str]           =						scope






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







							"""simple docstring"""


							snake_case_		:      List[Any]           =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

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

							snake_case_		:      int           =						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 UpperCAmelCase_					(   self   :   int		, _A   :   Dict		, _A   :   Dict		, _A   :   List[str]						)				->     Optional[Any]:







							"""simple docstring"""


							snake_case_		:      Dict           =						PoolFormerModel(config=_A						)
							model.to(_A						)
							model.eval()
							snake_case_		:      List[Any]           =						model(_A						)
							snake_case_		:      Dict           =						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 UpperCAmelCase_					(   self   :   Any						)				->     Tuple:







							"""simple docstring"""


							snake_case_		:      int           =						self.prepare_config_and_inputs()
							snake_case_    ,snake_case_    ,snake_case_		:      Tuple           =						config_and_inputs
							snake_case_		:      str           =						{'pixel_values': pixel_values}
							return config, inputs_dict
@require_torch
class SCREAMING_SNAKE_CASE_    (       snake_case_							,					snake_case_							,					unittest.TestCase       ):
						__magic_name__:      int			   =							(PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else ()
						__magic_name__:      Dict			   =							(
						    {"feature-extraction": PoolFormerModel, "image-classification": PoolFormerForImageClassification}
						    if is_torch_available()
						    else {}
						)

						__magic_name__:      List[Any]			   =							False
						__magic_name__:      str			   =							False
						__magic_name__:      List[Any]			   =							False
						__magic_name__:      Tuple			   =							False
						__magic_name__:      List[str]			   =							False






						def UpperCAmelCase_					(   self   :   int						)				->     Dict:







							"""simple docstring"""


							snake_case_		:      int           =						PoolFormerModelTester(self						)
							snake_case_		:      Optional[int]           =						PoolFormerConfigTester(self		, config_class=_A						)






						def UpperCAmelCase_					(   self   :   Dict						)				->     Any:







							"""simple docstring"""


							self.config_tester.run_common_tests()






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







							"""simple docstring"""


							snake_case_		:      Union[str, Any]           =						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_A						)






						@unittest.skip('PoolFormer does not use inputs_embeds'						)
						def UpperCAmelCase_					(   self   :   int						)				->     Union[str, Any]:







							"""simple docstring"""


							pass






						@unittest.skip('PoolFormer does not have get_input_embeddings method and get_output_embeddings methods'						)
						def UpperCAmelCase_					(   self   :   int						)				->     Union[str, Any]:







							"""simple docstring"""


							pass






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







							"""simple docstring"""


							def check_hidden_states_output(_A   :   Optional[int]		, _A   :   Optional[Any]		, _A   :   Union[str, Any]						):
								snake_case_		:      str           =						model_class(_A						)
								model.to(_A						)
								model.eval()

								with torch.no_grad():
									snake_case_		:      str           =						model(**self._prepare_for_class(_A		, _A						)						)

								snake_case_		:      Optional[int]           =						outputs.hidden_states

								snake_case_		:      str           =						self.model_tester.num_encoder_blocks
								self.assertEqual(len(_A						)		, _A						)

								# 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,
								    ]		, )

							snake_case_    ,snake_case_		:      int           =						self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
								snake_case_		:      Tuple           =						True
								check_hidden_states_output(_A		, _A		, _A						)

								# check that output_hidden_states also work using config
								del inputs_dict["output_hidden_states"]
								snake_case_		:      Dict           =						True

								check_hidden_states_output(_A		, _A		, _A						)






						def UpperCAmelCase_					(   self   :   List[str]						)				->     Optional[int]:







							"""simple docstring"""


							if not self.model_tester.is_training:
								return

							snake_case_    ,snake_case_		:      Optional[Any]           =						self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_		:      Optional[int]           =						True

							for model_class in self.all_model_classes:
								if model_class in get_values(_A						):
									continue
								snake_case_		:      List[Any]           =						model_class(_A						)
								model.to(_A						)
								model.train()
								snake_case_		:      Tuple           =						self._prepare_for_class(_A		, _A		, return_labels=_A						)
								snake_case_		:      str           =						model(**_A						).loss
								loss.backward()






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







							"""simple docstring"""


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

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

								snake_case_		:      int           =						['pixel_values']
								self.assertListEqual(arg_names[:1]		, _A						)






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







							"""simple docstring"""


							for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								snake_case_		:      Optional[Any]           =						PoolFormerModel.from_pretrained(_A						)
								self.assertIsNotNone(_A						)


def 				SCREAMING_SNAKE_CASE__    (     ):
	snake_case_		:      Dict           =						Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png' )
	return image


@require_torch
class SCREAMING_SNAKE_CASE_    (       unittest.TestCase       ):






						@slow
						def UpperCAmelCase_					(   self   :   Optional[int]						)				->     int:







							"""simple docstring"""


							snake_case_		:      Tuple           =						PoolFormerImageProcessor()
							snake_case_		:      int           =						PoolFormerForImageClassification.from_pretrained('sail/poolformer_s12'						).to(_A						)

							snake_case_		:      Optional[int]           =						image_processor(images=prepare_img()		, return_tensors='pt'						).to(_A						)

							# forward pass
							with torch.no_grad():
								snake_case_		:      int           =						model(**_A						)

							# verify the logits
							snake_case_		:      Tuple           =						torch.Size((1, 1000)						)
							self.assertEqual(outputs.logits.shape		, _A						)

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


"""simple docstring"""







from collections import Counter



def       A__    (	lowercase_     :	list[int]						)  ->							int:
   return sum(socks_by_color // 2 for socks_by_color in Counter(lowercase_						).values()						)


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     _SCREAMING_SNAKE_CASE	:		int   =   [int(x) for x in input('''Enter socks by color :''').rstrip().split()]
     print(F"sock_merchant({colors}) = {sock_merchant(colors)}")






