





import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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 MobileNetVaForImageClassification, MobileNetVaModel
 from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import MobileNetVaImageProcessor


class        __magic_name__	(				lowerCamelCase__				):





     """simple docstring"""



     def     SCREAMING_SNAKE_CASE		(				self							:int	):





        '''simple docstring'''




        A_       :					Dict        =      self.config_class(**self.inputs_dict	)
        self.parent.assertTrue(hasattr(snake_case      ,   "tf_padding"	)	)
        self.parent.assertTrue(hasattr(snake_case      ,   "depth_multiplier"	)	)




class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:List[Any]      ,   snake_case							:Optional[Any]      ,   snake_case							:Optional[int]=13      ,   snake_case							:Any=3      ,   snake_case							:str=32      ,   snake_case							:int=0.25      ,   snake_case							:List[str]=8      ,   snake_case							:Optional[Any]=True      ,   snake_case							:Tuple=1_024      ,   snake_case							:int=32      ,   snake_case							:str="relu6"      ,   snake_case							:List[Any]=0.1      ,   snake_case							:Any=0.02      ,   snake_case							:List[Any]=True      ,   snake_case							:str=True      ,   snake_case							:str=10      ,   snake_case							:Dict=None      ,   ):





        '''simple docstring'''




        A_       :					Tuple        =      parent
        A_       :					str        =      batch_size
        A_       :					Any        =      num_channels
        A_       :					Any        =      image_size
        A_       :					List[Any]        =      depth_multiplier
        A_       :					Optional[int]        =      min_depth
        A_       :					str        =      tf_padding
        A_       :					List[str]        =      int(last_hidden_size * depth_multiplier	)
        A_       :					List[Any]        =      output_stride
        A_       :					Union[str, Any]        =      hidden_act
        A_       :					Tuple        =      classifier_dropout_prob
        A_       :					List[str]        =      use_labels
        A_       :					Union[str, Any]        =      is_training
        A_       :					Tuple        =      num_labels
        A_       :					Optional[int]        =      initializer_range
        A_       :					List[str]        =      scope



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





        '''simple docstring'''




        A_       :					int        =      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

        A_       :					Any        =      None
        A_       :					Union[str, Any]        =      None
        if self.use_labels:
           A_       :					Optional[int]        =      ids_tensor([self.batch_size]      ,   self.num_labels	)
           A_       :					Any        =      ids_tensor([self.batch_size, self.image_size, self.image_size]      ,   self.num_labels	)

        A_       :					List[Any]        =      self.get_config()

        return config, pixel_values, labels, pixel_labels



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        return MobileNetVaConfig(
            num_channels=self.num_channels      ,   image_size=self.image_size      ,   depth_multiplier=self.depth_multiplier      ,   min_depth=self.min_depth      ,   tf_padding=self.tf_padding      ,   hidden_act=self.hidden_act      ,   classifier_dropout_prob=self.classifier_dropout_prob      ,   initializer_range=self.initializer_range      ,   )



     def     SCREAMING_SNAKE_CASE		(				self							:Any      ,   snake_case							:Union[str, Any]      ,   snake_case							:int      ,   snake_case							:Tuple      ,   snake_case							:Tuple	):





        '''simple docstring'''




        A_       :					Any        =      MobileNetVaModel(config=snake_case	)
        model.to(snake_case	)
        model.eval()
        A_       :					Tuple        =      model(snake_case	)
        self.parent.assertEqual(
            result.last_hidden_state.shape      ,   (
                self.batch_size,
                self.last_hidden_size,
                self.image_size // self.output_stride,
                self.image_size // self.output_stride,
            )      ,   )



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]      ,   snake_case							:int      ,   snake_case							:List[str]      ,   snake_case							:Dict      ,   snake_case							:List[str]	):





        '''simple docstring'''




        A_       :					Dict        =      self.num_labels
        A_       :					Optional[int]        =      MobileNetVaForImageClassification(snake_case	)
        model.to(snake_case	)
        model.eval()
        A_       :					Optional[Any]        =      model(snake_case      ,   labels=snake_case	)
        self.parent.assertEqual(result.logits.shape      ,   (self.batch_size, self.num_labels)	)





     def     SCREAMING_SNAKE_CASE		(				self							:Optional[int]	):





        '''simple docstring'''




        A_       :					Any        =      self.prepare_config_and_inputs()
        A_   ,    A_   ,    A_   ,    A_       :					Optional[int]        =      config_and_inputs
        A_       :					Union[str, Any]        =      {"pixel_values": pixel_values}
        return config, inputs_dict




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





     """simple docstring"""



     __UpperCamelCase            =  (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
     __UpperCamelCase            =  (
         {'''feature-extraction''': MobileNetVaModel, '''image-classification''': MobileNetVaForImageClassification}
         if is_torch_available()
         else {}
     )

     __UpperCamelCase            =  False
     __UpperCamelCase            =  False
     __UpperCamelCase            =  False
     __UpperCamelCase            =  False



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]	):





        '''simple docstring'''




        A_       :					Any        =      MobileNetVaModelTester(self	)
        A_       :					Dict        =      MobileNetVaConfigTester(self      ,   config_class=snake_case      ,   has_text_modality=snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:List[str]	):





        '''simple docstring'''




        self.config_tester.run_common_tests()



     @unittest.skip(reason="MobileNetV1 does not use inputs_embeds"	)
     def     SCREAMING_SNAKE_CASE		(				self							:int	):





        '''simple docstring'''




        pass



     @unittest.skip(reason="MobileNetV1 does not support input and output embeddings"	)
     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        pass



     @unittest.skip(reason="MobileNetV1 does not output attentions"	)
     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]	):





        '''simple docstring'''




        pass



     def     SCREAMING_SNAKE_CASE		(				self							:Tuple	):





        '''simple docstring'''




        A_   ,    A_       :					Tuple        =      self.model_tester.prepare_config_and_inputs_for_common()

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

           A_       :					Union[str, Any]        =      ["pixel_values"]
           self.assertListEqual(arg_names[:1]      ,   snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




        A_       :					Optional[Any]        =      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*snake_case	)



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





        '''simple docstring'''




        def check_hidden_states_output(snake_case							:Union[str, Any]      ,   snake_case							:Any      ,   snake_case							:Union[str, Any]	):
           A_       :					Any        =      model_class(snake_case	)
           model.to(snake_case	)
           model.eval()

           with torch.no_grad():
              A_       :					int        =      model(**self._prepare_for_class(snake_case      ,   snake_case	)	)

           A_       :					List[Any]        =      outputs.hidden_states

           A_       :					Tuple        =      26
           self.assertEqual(len(snake_case	)      ,   snake_case	)

        A_   ,    A_       :					Union[str, Any]        =      self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
           A_       :					Tuple        =      True
           check_hidden_states_output(snake_case      ,   snake_case      ,   snake_case	)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           A_       :					Optional[int]        =      True

           check_hidden_states_output(snake_case      ,   snake_case      ,   snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:int	):





        '''simple docstring'''




        A_       :					Union[str, Any]        =      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*snake_case	)





     @slow
     def     SCREAMING_SNAKE_CASE		(				self							:List[str]	):





        '''simple docstring'''




        for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           A_       :					List[Any]        =      MobileNetVaModel.from_pretrained(snake_case	)
           self.assertIsNotNone(snake_case	)




def   __snake_case    (       )			->    Any:
   A_       :					Optional[Any]        =      Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
   return image





@require_torch
@require_vision
class        __magic_name__	(				unittest.TestCase				):





     """simple docstring"""



     @cached_property
     def     SCREAMING_SNAKE_CASE		(				self							:Dict	):





        '''simple docstring'''




        return (
            MobileNetVaImageProcessor.from_pretrained("google/mobilenet_v1_1.0_224"	) if is_vision_available() else None
        )





     @slow
     def     SCREAMING_SNAKE_CASE		(				self							:Optional[int]	):





        '''simple docstring'''




        A_       :					str        =      MobileNetVaForImageClassification.from_pretrained("google/mobilenet_v1_1.0_224"	).to(snake_case	)

        A_       :					int        =      self.default_image_processor
        A_       :					Tuple        =      prepare_img()
        A_       :					Any        =      image_processor(images=snake_case      ,   return_tensors="pt"	).to(snake_case	)

        # forward pass
        with torch.no_grad():
           A_       :					Tuple        =      model(**snake_case	)

        # verify the logits
        A_       :					List[str]        =      torch.Size((1, 1_001)	)
        self.assertEqual(outputs.logits.shape      ,   snake_case	)

        A_       :					Dict        =      torch.tensor([-4.1739, -1.1233, 3.1205]	).to(snake_case	)

        self.assertTrue(torch.allclose(outputs.logits[0, :3]      ,   snake_case      ,   atol=1e-4	)	)







from __future__ import annotations

def   __snake_case    (       _lowerCAmelCase			:			list[int]					,					_lowerCAmelCase			:			int						)			->    list[list[int]]:
   A_       :					list[list[int]]        =      []
   A_       :					list[int]        =      []
   A_       :					Dict        =      0
   A_       :					str        =      sum(_lowerCAmelCase						)
   create_state_space_tree(_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase						)
   return result

def   __snake_case    (       _lowerCAmelCase			:			list[int]					,					_lowerCAmelCase			:			int					,					_lowerCAmelCase			:			int					,					_lowerCAmelCase			:			list[int]					,					_lowerCAmelCase			:			list[list[int]]					,					_lowerCAmelCase			:			int					,					)			->    None:
   if sum(_lowerCAmelCase						) > max_sum or (remaining_nums_sum + sum(_lowerCAmelCase						)) < max_sum:
      return
   if sum(_lowerCAmelCase						) == max_sum:
      result.append(_lowerCAmelCase						)
      return
   for index in range(_lowerCAmelCase					,					len(_lowerCAmelCase						)						):
      create_state_space_tree(
          _lowerCAmelCase					,					_lowerCAmelCase					,					index + 1					,					[*path, nums[index]]					,					_lowerCAmelCase					,					remaining_nums_sum - nums[index]					,					)
_lowerCAmelCase				:   List[Any]						       =						[3, 34, 4, 12, 5, 2]
_lowerCAmelCase				:   Dict						       =						9
_lowerCAmelCase				:   Dict						       =						generate_sum_of_subsets_soln(nums, max_sum)





print(*result)
