code: 
  
  
  """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    __A       ( _SCREAMING_SNAKE_CASE    ):
  
  
  
  
  
  
   """simple docstring"""
  
  
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Union[str, Any]:
       a					=self.config_class(**self.inputs_dict		)
       self.parent.assertTrue(hasattr(__A				,					'''hidden_sizes'''		)		)
       self.parent.assertTrue(hasattr(__A				,					'''num_encoder_blocks'''		)		)
  
  
  
  
  
  
  class    __A       :
  
  
  
  
  
  
   """simple docstring"""
  
  
  
  
   def __init__(	self				,					__A				,					__A=13				,					__A=64				,					__A=3				,					__A=4				,					__A=[2, 2, 2, 2]				,					__A=[8, 4, 2, 1]				,					__A=[16, 32, 64, 128]				,					__A=[1, 4, 8, 16]				,					__A=False				,					__A=True				,					__A="gelu"				,					__A=0.1				,					__A=0.02				,					__A=3				,					__A=None				,					)      ->  Tuple:
       a					=parent
       a					=batch_size
       a					=image_size
       a					=num_channels
       a					=num_encoder_blocks
       a					=sr_ratios
       a					=depths
       a					=hidden_sizes
       a					=downsampling_rates
       a					=is_training
       a					=use_labels
       a					=hidden_act
       a					=hidden_dropout_prob
       a					=initializer_range
       a					=num_labels
       a					=scope
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Dict:
       a					=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)
  
       a					=None
       if self.use_labels:
           a					=ids_tensor([self.batch_size, self.image_size, self.image_size]				,					self.num_labels		)
  
       a					=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    SCREAMING_SNAKE_CASE							(	self				,					__A				,					__A				,					__A		)      ->  Optional[int]:
       a					=PoolFormerModel(config=__A		)
       model.to(__A		)
       model.eval()
       a					=model(__A		)
       a					=a					=self.image_size // 32.0
       self.parent.assertEqual(
           result.last_hidden_state.shape				,					(self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)		)
  
  
  
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Optional[Any]:
       a					=self.prepare_config_and_inputs()
       a	,   a	,   a					=config_and_inputs
       a					={'''pixel_values''': pixel_values}
       return config, inputs_dict
  
  
  
  
  
  
  @require_torch
  class    __A       ( _SCREAMING_SNAKE_CASE,					_SCREAMING_SNAKE_CASE,					unittest.TestCase    ):
  
  
  
  
  
  
   """simple docstring"""
  
  
  
  
   __lowerCAmelCase				      =						(PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else ()
   __lowerCAmelCase				      =						(
       {"feature-extraction": PoolFormerModel, "image-classification": PoolFormerForImageClassification}
       if is_torch_available()
       else {}
   )
  
   __lowerCAmelCase				      =						False
   __lowerCAmelCase				      =						False
   __lowerCAmelCase				      =						False
   __lowerCAmelCase				      =						False
   __lowerCAmelCase				      =						False
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Union[str, Any]:
       a					=PoolFormerModelTester(self		)
       a					=PoolFormerConfigTester(self				,					config_class=__A		)
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  List[Any]:
       self.config_tester.run_common_tests()
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Tuple:
       a					=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__A		)
  
  
   @unittest.skip('''PoolFormer does not use inputs_embeds'''		)
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Dict:
       pass
  
  
   @unittest.skip('''PoolFormer does not have get_input_embeddings method and get_output_embeddings methods'''		)
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  int:
       pass
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Any:
       def check_hidden_states_output(__A				,					__A				,					__A		):
           a					=model_class(__A		)
           model.to(__A		)
           model.eval()
  
           with torch.no_grad():
               a					=model(**self._prepare_for_class(__A				,					__A		)		)
  
           a					=outputs.hidden_states
  
           a					=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,
               ]				,					)
  
       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(__A				,					__A				,					__A		)
  
           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           a					=True
  
           check_hidden_states_output(__A				,					__A				,					__A		)
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  str:
       if not self.model_tester.is_training:
           return
  
       a	,   a					=self.model_tester.prepare_config_and_inputs_for_common()
       a					=True
  
       for model_class in self.all_model_classes:
           if model_class in get_values(__A		):
               continue
           a					=model_class(__A		)
           model.to(__A		)
           model.train()
           a					=self._prepare_for_class(__A				,					__A				,					return_labels=__A		)
           a					=model(**__A		).loss
           loss.backward()
  
  
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  int:
       a	,   a					=self.model_tester.prepare_config_and_inputs_for_common()
  
       for model_class in self.all_model_classes:
           a					=model_class(__A		)
           a					=inspect.signature(model.forward		)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           a					=[*signature.parameters.keys()]
  
           a					=['''pixel_values''']
           self.assertListEqual(arg_names[:1]				,					__A		)
  
  
  
  
  
   @slow
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Dict:
       for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           a					=PoolFormerModel.from_pretrained(__A		)
           self.assertIsNotNone(__A		)
  
  def _A		(		):
  
  
  
  
  
  
  
      """simple docstring"""
      a					=Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''	)
      return image
  
  
  
  
  
  
  @require_torch
  class    __A       ( unittest.TestCase    ):
  
  
  
  
  
  
   """simple docstring"""
  
  
  
  
   @slow
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  List[str]:
       a					=PoolFormerImageProcessor()
       a					=PoolFormerForImageClassification.from_pretrained('''sail/poolformer_s12'''		).to(__A		)
  
       a					=image_processor(images=prepare_img()				,					return_tensors='''pt'''		).to(__A		)
  
       # forward pass
       with torch.no_grad():
           a					=model(**__A		)
  
       # verify the logits
       a					=torch.Size((1, 1000)		)
       self.assertEqual(outputs.logits.shape				,					__A		)
  
       a					=torch.tensor([-0.6_113, 0.1_685, -0.0_492]		).to(__A		)
       self.assertTrue(torch.allclose(outputs.logits[0, :3]				,					__A				,					atol=1E-4		)		)
style_context: 
  
  
  """simple docstring"""
  
  
  
  
  
  
  
  from collections import OrderedDict
  from typing import Mapping
  
  from packaging import version
  
  from ...configuration_utils import PretrainedConfig
  from ...onnx import OnnxConfig
  from ...utils import logging
  
  
  lowerCamelCase_     :     Any    		=						logging.get_logger(__name__)
  
  lowerCamelCase_     :     Tuple    		=						{
      """apple/mobilevitv2-1.0""": """https://huggingface.co/apple/mobilevitv2-1.0/resolve/main/config.json""",
  }
  
  
  
  
  
  
  class    __A       ( _SCREAMING_SNAKE_CASE    ):
  
  
  
  
  
  
   """simple docstring"""
  
  
  
  
   __lowerCAmelCase				      =						"mobilevitv2"
  
  
   def __init__(	self				,					__A=3				,					__A=256				,					__A=2				,					__A=2.0				,					__A="swish"				,					__A=3				,					__A=32				,					__A=0.1				,					__A=0.02				,					__A=1E-5				,					__A=512				,					__A=[6, 12, 18]				,					__A=0.1				,					__A=255				,					__A=[2, 4, 3]				,					__A=[128, 192, 256]				,					__A=1.0				,					__A=2				,					__A=0.0				,					__A=0.0				,					**__A				,					)      ->  int:
       super().__init__(**__A		)
  
       a					=num_channels
       a					=image_size
       a					=patch_size
       a					=expand_ratio
       a					=hidden_act
       a					=conv_kernel_size
       a					=output_stride
       a					=initializer_range
       a					=layer_norm_eps
       a					=n_attn_blocks
       a					=base_attn_unit_dims
       a					=width_multiplier
       a					=ffn_multiplier
       a					=ffn_dropout
       a					=attn_dropout
       a					=classifier_dropout_prob
  
       # decode head attributes for semantic segmentation
       a					=aspp_out_channels
       a					=atrous_rates
       a					=aspp_dropout_prob
       a					=semantic_loss_ignore_index
  
  
  
  
  
  
  class    __A       ( _SCREAMING_SNAKE_CASE    ):
  
  
  
  
  
  
   """simple docstring"""
  
  
  
  
   __lowerCAmelCase				      =						version.parse("1.11"    )
  
  
   @property
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Mapping[str, Mapping[int, str]]:
       return OrderedDict([('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''})]		)
  
  
   @property
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  Mapping[str, Mapping[int, str]]:
       if self.task == "image-classification":
           return OrderedDict([('''logits''', {0: '''batch'''})]		)
       else:
           return OrderedDict([('''last_hidden_state''', {0: '''batch'''}), ('''pooler_output''', {0: '''batch'''})]		)
  
  
  
  
  
   @property
   def    SCREAMING_SNAKE_CASE							(	self		)      ->  float:
       return 1E-4