code: 
  
  
  
  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 		_snake_case      (			lowerCamelCase				):
  
  
  
  
  
   """simple docstring"""
  
  
  
   def lowercase_		(						self					)	->							Union[str, Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.config_class(**self.inputs_dict					)
     self.parent.assertTrue(hasattr(a	,    '''hidden_sizes'''					)					)
     self.parent.assertTrue(hasattr(a	,    '''num_encoder_blocks'''					)					)
  
  
  
  
  
  
  
  class 		_snake_case      :
  
  
  
  
  
   """simple docstring"""
  
  
  
   def __init__(						self	,    a	,    a=1_3	,    a=6_4	,    a=3	,    a=4	,    a=[2, 2, 2, 2]	,    a=[8, 4, 2, 1]	,    a=[1_6, 3_2, 6_4, 1_2_8]	,    a=[1, 4, 8, 1_6]	,    a=False	,    a=True	,    a="gelu"	,    a=0.1	,    a=0.02	,    a=3	,    a=None	,    )	->							List[Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _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 lowercase_		(						self					)	->							Tuple:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _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 lowercase_		(						self	,    a	,    a	,    a					)	->							Optional[Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _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 lowercase_		(						self					)	->							Optional[Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.prepare_config_and_inputs()
     _A    ,   _A    ,   _A           =    config_and_inputs
     _A           =    {'''pixel_values''': pixel_values}
     return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class 		_snake_case      (			lowerCamelCase					,lowerCamelCase					,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 lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    PoolFormerModelTester(self					)
     _A           =    PoolFormerConfigTester(self	,    config_class=a					)
   def lowercase_		(						self					)	->							Any:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     self.config_tester.run_common_tests()
   def lowercase_		(						self					)	->							Optional[int]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _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 lowercase_		(						self					)	->							Optional[int]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     pass
   @unittest.skip('''PoolFormer does not have get_input_embeddings method and get_output_embeddings methods'''					)
   def lowercase_		(						self					)	->							Dict:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     pass
   def lowercase_		(						self					)	->							str:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     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 lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     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 lowercase_		(						self					)	->							Any:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _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 lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       _A           =    PoolFormerModel.from_pretrained(a					)
       self.assertIsNotNone(a					)
  
  
  
  
  
  
  
  def     UpperCAmelCase__ (							)   -> Dict:
    _A           =    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
    return image
  
  
  
  @require_torch
  class 		_snake_case      (			unittest.TestCase				):
  
  
  
  
  
   """simple docstring"""
  
  
  
   @slow
   def lowercase_		(						self					)	->							Dict:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _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, 1_0_0_0)					)
     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: 
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case						,				__snake_case						,				__snake_case						,				__snake_case							)   -> None:
    if target == 0:
      answer.append(path.copy()							)
    else:
      for index in range(__snake_case						,				len(__snake_case							)							):
        if target >= candidates[index]:
          path.append(candidates[index]							)
          backtrack(__snake_case						,				__snake_case						,				__snake_case						,				target - candidates[index]						,				__snake_case							)
          path.pop(len(__snake_case							) - 1							)
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case							)   -> list:
    _A           =    []  # type: list[int]
    _A           =    []  # type: list[int]
    backtrack(__snake_case						,				__snake_case						,				__snake_case						,				__snake_case						,				0							)
    return answer
  
  
  
  
  def     UpperCAmelCase__ (							)   -> None:
    print(combination_sum([-8, 2.3, 0]						,				1							)							)
  
  
  if __name__ == "__main__":
      import doctest
  
      doctest.testmod()
      main()