

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  __lowerCAmelCase     (					__snake_case							):




  def   A__     (				self					)  -> str:
        '''simple docstring'''






        _lowercase	       =self.config_class(**self.inputs_dict					)
        self.parent.assertTrue(hasattr(__SCREAMING_SNAKE_CASE							,   'tf_padding'					)					)
        self.parent.assertTrue(hasattr(__SCREAMING_SNAKE_CASE							,   'depth_multiplier'					)					)





class  __lowerCAmelCase     :




  def __init__(				self							,   lowerCAmelCase							,   lowerCAmelCase=13							,   lowerCAmelCase=3							,   lowerCAmelCase=32							,   lowerCAmelCase=0.25							,   lowerCAmelCase=8							,   lowerCAmelCase=True							,   lowerCAmelCase=1_024							,   lowerCAmelCase=32							,   lowerCAmelCase="relu6"							,   lowerCAmelCase=0.1							,   lowerCAmelCase=0.02							,   lowerCAmelCase=True							,   lowerCAmelCase=True							,   lowerCAmelCase=10							,   lowerCAmelCase=None							,   )  -> Union[str, Any]:
        '''simple docstring'''






        _lowercase	       =parent
        _lowercase	       =batch_size
        _lowercase	       =num_channels
        _lowercase	       =image_size
        _lowercase	       =depth_multiplier
        _lowercase	       =min_depth
        _lowercase	       =tf_padding
        _lowercase	       =int(last_hidden_size * depth_multiplier					)
        _lowercase	       =output_stride
        _lowercase	       =hidden_act
        _lowercase	       =classifier_dropout_prob
        _lowercase	       =use_labels
        _lowercase	       =is_training
        _lowercase	       =num_labels
        _lowercase	       =initializer_range
        _lowercase	       =scope




  def   A__     (				self					)  -> Tuple:
        '''simple docstring'''






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

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

        _lowercase	       =self.get_config()

        return config, pixel_values, labels, pixel_labels




  def   A__     (				self					)  -> Dict:
        '''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   A__     (				self							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase					)  -> Union[str, Any]:
        '''simple docstring'''






        _lowercase	       =MobileNetVaModel(config=__SCREAMING_SNAKE_CASE					)
        model.to(__SCREAMING_SNAKE_CASE					)
        model.eval()
        _lowercase	       =model(__SCREAMING_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   A__     (				self							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase					)  -> List[str]:
        '''simple docstring'''






        _lowercase	       =self.num_labels
        _lowercase	       =MobileNetVaForImageClassification(__SCREAMING_SNAKE_CASE					)
        model.to(__SCREAMING_SNAKE_CASE					)
        model.eval()
        _lowercase	       =model(__SCREAMING_SNAKE_CASE							,   labels=__SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.logits.shape							,   (self.batch_size, self.num_labels)					)




  def   A__     (				self					)  -> Any:
        '''simple docstring'''






        _lowercase	       =self.prepare_config_and_inputs()
        _lowercase       ,       _lowercase       ,       _lowercase       ,       _lowercase	       =config_and_inputs
        _lowercase	       ={'pixel_values': pixel_values}
        return config, inputs_dict





@require_torch
class  __lowerCAmelCase     (					__snake_case			,			__snake_case			,			unittest.TestCase							):
  _a									=  (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
  _a									=  (
      {"""feature-extraction""": MobileNetVaModel, """image-classification""": MobileNetVaForImageClassification}
      if is_torch_available()
      else {}
  )

  _a									=  False
  _a									=  False
  _a									=  False
  _a									=  False




  def   A__     (				self					)  -> Optional[Any]:
        '''simple docstring'''






        _lowercase	       =MobileNetVaModelTester(self					)
        _lowercase	       =MobileNetVaConfigTester(self							,   config_class=__SCREAMING_SNAKE_CASE							,   has_text_modality=__SCREAMING_SNAKE_CASE					)




  def   A__     (				self					)  -> List[Any]:
        '''simple docstring'''






        self.config_tester.run_common_tests()




  @unittest.skip(reason='MobileNetV1 does not use inputs_embeds'					)
  def   A__     (				self					)  -> str:
        '''simple docstring'''






        pass




  @unittest.skip(reason='MobileNetV1 does not support input and output embeddings'					)
  def   A__     (				self					)  -> Tuple:
        '''simple docstring'''






        pass




  @unittest.skip(reason='MobileNetV1 does not output attentions'					)
  def   A__     (				self					)  -> Dict:
        '''simple docstring'''






        pass




  def   A__     (				self					)  -> List[str]:
        '''simple docstring'''






        _lowercase       ,       _lowercase	       =self.model_tester.prepare_config_and_inputs_for_common()

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

              _lowercase	       =['pixel_values']
              self.assertListEqual(arg_names[:1]							,   __SCREAMING_SNAKE_CASE					)




  def   A__     (				self					)  -> Dict:
        '''simple docstring'''






        _lowercase	       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE					)




  def   A__     (				self					)  -> Tuple:
        '''simple docstring'''






        def check_hidden_states_output(lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase					):
              _lowercase	       =model_class(__SCREAMING_SNAKE_CASE					)
              model.to(__SCREAMING_SNAKE_CASE					)
              model.eval()

              with torch.no_grad():
                    _lowercase	       =model(**self._prepare_for_class(__SCREAMING_SNAKE_CASE							,   __SCREAMING_SNAKE_CASE					)					)

              _lowercase	       =outputs.hidden_states

              _lowercase	       =26
              self.assertEqual(len(__SCREAMING_SNAKE_CASE					)							,   __SCREAMING_SNAKE_CASE					)

        _lowercase       ,       _lowercase	       =self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
              _lowercase	       =True
              check_hidden_states_output(__SCREAMING_SNAKE_CASE							,   __SCREAMING_SNAKE_CASE							,   __SCREAMING_SNAKE_CASE					)

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

              check_hidden_states_output(__SCREAMING_SNAKE_CASE							,   __SCREAMING_SNAKE_CASE							,   __SCREAMING_SNAKE_CASE					)




  def   A__     (				self					)  -> Optional[int]:
        '''simple docstring'''






        _lowercase	       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*__SCREAMING_SNAKE_CASE					)




  @slow
  def   A__     (				self					)  -> str:
        '''simple docstring'''






        for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              _lowercase	       =MobileNetVaModel.from_pretrained(__SCREAMING_SNAKE_CASE					)
              self.assertIsNotNone(__SCREAMING_SNAKE_CASE					)
def      a      (			)    ->      Dict:





      """simple docstring"""



      _lowercase	       =Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
      return image







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




  @cached_property
  def   A__     (				self					)  -> Optional[int]:
        '''simple docstring'''






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




  @slow
  def   A__     (				self					)  -> str:
        '''simple docstring'''






        _lowercase	       =MobileNetVaForImageClassification.from_pretrained('google/mobilenet_v1_1.0_224'					).to(__SCREAMING_SNAKE_CASE					)

        _lowercase	       =self.default_image_processor
        _lowercase	       =prepare_img()
        _lowercase	       =image_processor(images=__SCREAMING_SNAKE_CASE							,   return_tensors='pt'					).to(__SCREAMING_SNAKE_CASE					)

        # forward pass
        with torch.no_grad():
              _lowercase	       =model(**__SCREAMING_SNAKE_CASE					)

        # verify the logits
        _lowercase	       =torch.Size((1, 1_001)					)
        self.assertEqual(outputs.logits.shape							,   __SCREAMING_SNAKE_CASE					)

        _lowercase	       =torch.tensor([-4.1739, -1.1233, 3.1205]					).to(__SCREAMING_SNAKE_CASE					)

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










"""simple docstring"""





from __future__ import annotations







def      lowerCamelCase__       (							_lowerCamelCase       :		int )      ->				list[int]:
  lowerCamelCase_         =						[True] * limit
  lowerCamelCase_         =						False
  lowerCamelCase_         =						False
  lowerCamelCase_         =						True

  for i in range(3		,				int(limit**0.5 + 1 )		,				2 ):
    lowerCamelCase_         =						i * 2
    while index < limit:
      lowerCamelCase_         =						False
      lowerCamelCase_         =						index + i

  lowerCamelCase_         =						[2]

  for i in range(3		,				_lowerCamelCase		,				2 ):
    if is_prime[i]:
      primes.append(_lowerCamelCase )

  return primes







def      lowerCamelCase__       (							_lowerCamelCase       :		int = 1000000 )      ->				int:
  lowerCamelCase_         =						prime_sieve(_lowerCamelCase )
  lowerCamelCase_         =						0
  lowerCamelCase_         =						0

  for i in range(len(_lowerCamelCase ) ):
    for j in range(i + length		,				len(_lowerCamelCase ) ):
      lowerCamelCase_         =						sum(primes[i:j] )
      if sol >= ceiling:
        break

      if sol in primes:
        lowerCamelCase_         =						j - i
        lowerCamelCase_         =						sol

  return largest


if __name__ == "__main__":
  print(F'''{solution() = }''')




