

'''simple docstring'''






import inspect
import unittest
import warnings
from typing import List

from transformers import EfficientFormerConfig
from transformers.models.auto import get_values
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 (
          MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
          MODEL_MAPPING,
          EfficientFormerForImageClassification,
          EfficientFormerForImageClassificationWithTeacher,
          EfficientFormerModel,
      )
      from transformers.models.efficientformer.modeling_efficientformer import (
          EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
      )


if is_vision_available():
      from PIL import Image

      from transformers import EfficientFormerImageProcessor
class 	SCREAMING_SNAKE_CASE__			:




    def __init__(					self				,     lowercase__				,     lowercase__ = 13				,     lowercase__ = 64				,     lowercase__ = 2				,     lowercase__ = 3				,     lowercase__ = 3				,     lowercase__ = True				,     lowercase__ = True				,     lowercase__ = 128				,     lowercase__=[16, 32, 64, 128]				,     lowercase__ = 7				,     lowercase__ = 4				,     lowercase__ = 37				,     lowercase__ = "gelu"				,     lowercase__ = 0.1				,     lowercase__ = 0.1				,     lowercase__ = 10				,     lowercase__ = 0.02				,     lowercase__ = 2				,     lowercase__ = 1				,     lowercase__ = 128				,     lowercase__ = [2, 2, 2, 2]				,     lowercase__ = 2				,     lowercase__ = 2				,     ):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Any     =       parent
          SCREAMING_SNAKE_CASE_      :			int     =       batch_size
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       image_size
          SCREAMING_SNAKE_CASE_      :			List[str]     =       patch_size
          SCREAMING_SNAKE_CASE_      :			Any     =       num_channels
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       is_training
          SCREAMING_SNAKE_CASE_      :			str     =       use_labels
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       hidden_size
          SCREAMING_SNAKE_CASE_      :			List[str]     =       num_hidden_layers
          SCREAMING_SNAKE_CASE_      :			str     =       num_attention_heads
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       intermediate_size
          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       hidden_act
          SCREAMING_SNAKE_CASE_      :			List[str]     =       hidden_dropout_prob
          SCREAMING_SNAKE_CASE_      :			str     =       attention_probs_dropout_prob
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       type_sequence_label_size
          SCREAMING_SNAKE_CASE_      :			List[str]     =       initializer_range
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       encoder_stride
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       num_attention_outputs
          SCREAMING_SNAKE_CASE_      :			Any     =       embed_dim
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       embed_dim + 1
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       resolution
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       depths
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       hidden_sizes
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       dim
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       mlp_expansion_ratio




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






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

          SCREAMING_SNAKE_CASE_      :			List[Any]     =       None
          if self.use_labels:
                SCREAMING_SNAKE_CASE_      :			List[Any]     =       ids_tensor([self.batch_size]				,     self.type_sequence_label_size			)

          SCREAMING_SNAKE_CASE_      :			List[Any]     =       self.get_config()
          return config, pixel_values, labels




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return EfficientFormerConfig(
              image_size=self.image_size				,     patch_size=self.patch_size				,     num_channels=self.num_channels				,     hidden_size=self.hidden_size				,     num_hidden_layers=self.num_hidden_layers				,     num_attention_heads=self.num_attention_heads				,     intermediate_size=self.intermediate_size				,     hidden_act=self.hidden_act				,     hidden_dropout_prob=self.hidden_dropout_prob				,     attention_probs_dropout_prob=self.attention_probs_dropout_prob				,     is_decoder=lowercase__				,     initializer_range=self.initializer_range				,     encoder_stride=self.encoder_stride				,     resolution=self.resolution				,     depths=self.depths				,     hidden_sizes=self.hidden_sizes				,     dim=self.dim				,     mlp_expansion_ratio=self.mlp_expansion_ratio				,     )




    def   __lowerCamelCase      (					self				,     lowercase__				,     lowercase__				,     lowercase__			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       EfficientFormerModel(config=lowercase__			)
          model.to(lowercase__			)
          model.eval()
          SCREAMING_SNAKE_CASE_      :			Tuple     =       model(lowercase__			)
          self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)			)




    def   __lowerCamelCase      (					self				,     lowercase__				,     lowercase__				,     lowercase__			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			List[str]     =       self.type_sequence_label_size
          SCREAMING_SNAKE_CASE_      :			str     =       EfficientFormerForImageClassification(lowercase__			)
          model.to(lowercase__			)
          model.eval()
          SCREAMING_SNAKE_CASE_      :			List[str]     =       model(lowercase__				,     labels=lowercase__			)
          self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.type_sequence_label_size)			)

          # test greyscale images
          SCREAMING_SNAKE_CASE_      :			int     =       1
          SCREAMING_SNAKE_CASE_      :			Dict     =       EfficientFormerForImageClassification(lowercase__			)
          model.to(lowercase__			)
          model.eval()

          SCREAMING_SNAKE_CASE_      :			Any     =       floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
          SCREAMING_SNAKE_CASE_      :			str     =       model(lowercase__			)
          self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.type_sequence_label_size)			)







    def   __lowerCamelCase      (					self			):






          """simple docstring"""






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






@require_torch
class 	SCREAMING_SNAKE_CASE__			(				_UpperCAmelCase,_UpperCAmelCase,unittest.TestCase      ):
    _A			    =							(
        (
            EfficientFormerModel,
            EfficientFormerForImageClassificationWithTeacher,
            EfficientFormerForImageClassification,
        )
        if is_torch_available()
        else ()
    )
    _A			    =							(
        {
            "feature-extraction": EfficientFormerModel,
            "image-classification": (
                EfficientFormerForImageClassification,
                EfficientFormerForImageClassificationWithTeacher,
            ),
        }
        if is_torch_available()
        else {}
    )
    _A			    =							False

    _A			    =							False
    _A			    =							False
    _A			    =							False




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			List[str]     =       EfficientFormerModelTester(self			)
          SCREAMING_SNAKE_CASE_      :			Tuple     =       ConfigTester(
              self				,     config_class=lowercase__				,     has_text_modality=lowercase__				,     hidden_size=37			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          self.config_tester.run_common_tests()




    @unittest.skip(reason="EfficientFormer does not use inputs_embeds"			)
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          pass




    @unittest.skip(reason="EfficientFormer does not support input and output embeddings"			)
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          pass




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			str     =       self.model_tester.prepare_config_and_inputs_for_common()

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

                SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       ["pixel_values"]
                self.assertListEqual(arg_names[:1]				,     lowercase__			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          def check_hidden_states_output(lowercase__				,     lowercase__				,     lowercase__			):
                SCREAMING_SNAKE_CASE_      :			int     =       model_class(lowercase__			)
                model.to(lowercase__			)
                model.eval()

                with torch.no_grad():
                      SCREAMING_SNAKE_CASE_      :			Any     =       model(**self._prepare_for_class(lowercase__				,     lowercase__			)			)

                SCREAMING_SNAKE_CASE_      :			Any     =       outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

                SCREAMING_SNAKE_CASE_      :			Any     =       getattr(
                    self.model_tester				,     "expected_num_hidden_layers"				,     self.model_tester.num_hidden_layers + 1			)
                self.assertEqual(len(lowercase__			)				,     lowercase__			)

                if hasattr(self.model_tester				,     "encoder_seq_length"			):
                      SCREAMING_SNAKE_CASE_      :			str     =       self.model_tester.encoder_seq_length
                      if hasattr(self.model_tester				,     "chunk_length"			) and self.model_tester.chunk_length > 1:
                            SCREAMING_SNAKE_CASE_      :			List[str]     =       seq_length * self.model_tester.chunk_length
                else:
                      SCREAMING_SNAKE_CASE_      :			Any     =       self.model_tester.seq_length

                self.assertListEqual(
                    list(hidden_states[-1].shape[-2:]			)				,     [seq_length, self.model_tester.hidden_size]				,     )

                if config.is_encoder_decoder:
                      SCREAMING_SNAKE_CASE_      :			List[Any]     =       outputs.decoder_hidden_states

                      self.assertIsInstance(lowercase__				,     (list, tuple)			)
                      self.assertEqual(len(lowercase__			)				,     lowercase__			)
                      SCREAMING_SNAKE_CASE_      :			int     =       getattr(self.model_tester				,     "seq_length"				,     lowercase__			)
                      SCREAMING_SNAKE_CASE_      :			Optional[int]     =       getattr(self.model_tester				,     "decoder_seq_length"				,     lowercase__			)

                      self.assertListEqual(
                          list(hidden_states[-1].shape[-2:]			)				,     [decoder_seq_length, self.model_tester.hidden_size]				,     )

          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			Any     =       self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
                SCREAMING_SNAKE_CASE_      :			Optional[int]     =       True
                check_hidden_states_output(lowercase__				,     lowercase__				,     lowercase__			)

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

                check_hidden_states_output(lowercase__				,     lowercase__				,     lowercase__			)




    def   __lowerCamelCase      (					self				,     lowercase__				,     lowercase__				,     lowercase__=False			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			int     =       super()._prepare_for_class(lowercase__				,     lowercase__				,     return_labels=lowercase__			)

          if return_labels:
                if model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher":
                      del inputs_dict["labels"]

          return inputs_dict




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






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




    @unittest.skip(reason="EfficientFormer does not implement masked image modeling yet"			)
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_image_modeling(*lowercase__			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			str     =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*lowercase__			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          if not self.model_tester.is_training:
                return

          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			str     =       self.model_tester.prepare_config_and_inputs_for_common()
          SCREAMING_SNAKE_CASE_      :			str     =       True

          for model_class in self.all_model_classes:
                # EfficientFormerForImageClassificationWithTeacher supports inference-only
                if (
                    model_class in get_values(lowercase__			)
                    or model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher"
                ):
                      continue
                SCREAMING_SNAKE_CASE_      :			List[Any]     =       model_class(lowercase__			)
                model.to(lowercase__			)
                model.train()
                SCREAMING_SNAKE_CASE_      :			str     =       self._prepare_for_class(lowercase__				,     lowercase__				,     return_labels=lowercase__			)
                SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       model(**lowercase__			).loss
                loss.backward()




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			str     =       self.model_tester.prepare_config_and_inputs_for_common()

          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       [
              {"title": "multi_label_classification", "num_labels": 2, "dtype": torch.float},
              {"title": "single_label_classification", "num_labels": 1, "dtype": torch.long},
              {"title": "regression", "num_labels": 1, "dtype": torch.float},
          ]

          for model_class in self.all_model_classes:
                if (
                    model_class
                    not in [
                        *get_values(lowercase__			),
                    ]
                    or model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher"
                ):
                      continue

                for problem_type in problem_types:
                      with self.subTest(msg=F"Testing {model_class} with {problem_type['title']}"			):
                            SCREAMING_SNAKE_CASE_      :			Optional[int]     =       problem_type["title"]
                            SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       problem_type["num_labels"]

                            SCREAMING_SNAKE_CASE_      :			str     =       model_class(lowercase__			)
                            model.to(lowercase__			)
                            model.train()

                            SCREAMING_SNAKE_CASE_      :			int     =       self._prepare_for_class(lowercase__				,     lowercase__				,     return_labels=lowercase__			)

                            if problem_type["num_labels"] > 1:
                                  SCREAMING_SNAKE_CASE_      :			Tuple     =       inputs["labels"].unsqueeze(1			).repeat(1				,     problem_type["num_labels"]			)

                            SCREAMING_SNAKE_CASE_      :			Optional[int]     =       inputs["labels"].to(problem_type["dtype"]			)

                            # This tests that we do not trigger the warning form PyTorch "Using a target size that is different
                            # to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
                            # they have the same size." which is a symptom something in wrong for the regression problem.
                            # See https://github.com/huggingface/transformers/issues/11780
                            with warnings.catch_warnings(record=lowercase__			) as warning_list:
                                  SCREAMING_SNAKE_CASE_      :			str     =       model(**lowercase__			).loss
                            for w in warning_list:
                                  if "Using a target size that is different to the input size" in str(w.message			):
                                        raise ValueError(
                                            F"Something is going wrong in the regression problem: intercepted {w.message}"			)

                            loss.backward()




    @slow
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          for model_name in EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                SCREAMING_SNAKE_CASE_      :			Any     =       EfficientFormerModel.from_pretrained(lowercase__			)
                self.assertIsNotNone(lowercase__			)







    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			List[str]     =       self.model_tester.prepare_config_and_inputs_for_common()
          SCREAMING_SNAKE_CASE_      :			Any     =       True

          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       getattr(self.model_tester				,     "seq_length"				,     lowercase__			)
          SCREAMING_SNAKE_CASE_      :			int     =       getattr(self.model_tester				,     "encoder_seq_length"				,     lowercase__			)
          SCREAMING_SNAKE_CASE_      :			Dict     =       getattr(self.model_tester				,     "key_length"				,     lowercase__			)
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       getattr(self.model_tester				,     "chunk_length"				,     lowercase__			)

          if chunk_length is not None and hasattr(self.model_tester				,     "num_hashes"			):
                SCREAMING_SNAKE_CASE_      :			int     =       encoder_seq_length * self.model_tester.num_hashes

          for model_class in self.all_model_classes:
                SCREAMING_SNAKE_CASE_      :			Any     =       True
                SCREAMING_SNAKE_CASE_      :			int     =       False
                SCREAMING_SNAKE_CASE_      :			Any     =       True
                SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       model_class(lowercase__			)
                model.to(lowercase__			)
                model.eval()
                with torch.no_grad():
                      SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       model(**self._prepare_for_class(lowercase__				,     lowercase__			)			)
                SCREAMING_SNAKE_CASE_      :			List[Any]     =       outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
                self.assertEqual(len(lowercase__			)				,     self.model_tester.num_attention_outputs			)

                # check that output_attentions also work using config
                del inputs_dict["output_attentions"]
                SCREAMING_SNAKE_CASE_      :			Dict     =       True
                SCREAMING_SNAKE_CASE_      :			Optional[int]     =       model_class(lowercase__			)
                model.to(lowercase__			)
                model.eval()
                with torch.no_grad():
                      SCREAMING_SNAKE_CASE_      :			Optional[int]     =       model(**self._prepare_for_class(lowercase__				,     lowercase__			)			)
                SCREAMING_SNAKE_CASE_      :			List[Any]     =       outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
                self.assertEqual(len(lowercase__			)				,     self.model_tester.num_attention_outputs			)

                if chunk_length is not None:
                      self.assertListEqual(
                          list(attentions[0].shape[-4:]			)				,     [self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length]				,     )
                else:
                      self.assertListEqual(
                          list(attentions[0].shape[-3:]			)				,     [self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length]				,     )






def 					__lowerCamelCase			(      )							->   Any:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			Tuple     =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    )
      return image





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




    @cached_property
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return (
              EfficientFormerImageProcessor.from_pretrained("snap-research/efficientformer-l1-300"			)
              if is_vision_available()
              else None
          )




    @slow
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			int     =       EfficientFormerForImageClassification.from_pretrained("snap-research/efficientformer-l1-300"			).to(
              lowercase__			)

          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       self.default_image_processor
          SCREAMING_SNAKE_CASE_      :			Any     =       prepare_img()
          SCREAMING_SNAKE_CASE_      :			List[str]     =       image_processor(images=lowercase__				,     return_tensors="pt"			).to(lowercase__			)

          # forward pass
          with torch.no_grad():
                SCREAMING_SNAKE_CASE_      :			int     =       model(**lowercase__			)

          # verify the logits
          SCREAMING_SNAKE_CASE_      :			Dict     =       (1, 1000)
          self.assertEqual(outputs.logits.shape				,     lowercase__			)

          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       torch.tensor([-0.0555, 0.4825, -0.0852]			).to(lowercase__			)
          self.assertTrue(torch.allclose(outputs.logits[0][:3]				,     lowercase__				,     atol=1e-4			)			)







    @slow
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       EfficientFormerForImageClassificationWithTeacher.from_pretrained(
              "snap-research/efficientformer-l1-300"			).to(lowercase__			)

          SCREAMING_SNAKE_CASE_      :			List[Any]     =       self.default_image_processor
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       prepare_img()
          SCREAMING_SNAKE_CASE_      :			Tuple     =       image_processor(images=lowercase__				,     return_tensors="pt"			).to(lowercase__			)

          # forward pass
          with torch.no_grad():
                SCREAMING_SNAKE_CASE_      :			List[str]     =       model(**lowercase__			)

          # verify the logits
          SCREAMING_SNAKE_CASE_      :			List[str]     =       (1, 1000)
          self.assertEqual(outputs.logits.shape				,     lowercase__			)

          SCREAMING_SNAKE_CASE_      :			List[Any]     =       torch.tensor([-0.1312, 0.4353, -1.0499]			).to(lowercase__			)
          self.assertTrue(torch.allclose(outputs.logits[0][:3]				,     lowercase__				,     atol=1e-4			)			)




'''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


snake_case_       =       logging.get_logger(__name__)

snake_case_       =       {
    'apple/mobilevit-small': 'https://huggingface.co/apple/mobilevit-small/resolve/main/config.json',
    'apple/mobilevit-x-small': 'https://huggingface.co/apple/mobilevit-x-small/resolve/main/config.json',
    'apple/mobilevit-xx-small': 'https://huggingface.co/apple/mobilevit-xx-small/resolve/main/config.json',
    'apple/deeplabv3-mobilevit-small': (
        'https://huggingface.co/apple/deeplabv3-mobilevit-small/resolve/main/config.json'
    ),
    'apple/deeplabv3-mobilevit-x-small': (
        'https://huggingface.co/apple/deeplabv3-mobilevit-x-small/resolve/main/config.json'
    ),
    'apple/deeplabv3-mobilevit-xx-small': (
        'https://huggingface.co/apple/deeplabv3-mobilevit-xx-small/resolve/main/config.json'
    ),
    # See all MobileViT models at https://huggingface.co/models?filter=mobilevit
}
class 	SCREAMING_SNAKE_CASE__			(				_UpperCAmelCase      ):
    _A			    =							"mobilevit"




    def __init__(					self				,     lowercase__=3				,     lowercase__=256				,     lowercase__=2				,     lowercase__=[144, 192, 240]				,     lowercase__=[16, 32, 64, 96, 128, 160, 640]				,     lowercase__=4				,     lowercase__=2.0				,     lowercase__=4.0				,     lowercase__="silu"				,     lowercase__=3				,     lowercase__=32				,     lowercase__=0.1				,     lowercase__=0.0				,     lowercase__=0.1				,     lowercase__=0.02				,     lowercase__=1e-5				,     lowercase__=True				,     lowercase__=256				,     lowercase__=[6, 12, 18]				,     lowercase__=0.1				,     lowercase__=255				,     **lowercase__				,     ):






          """simple docstring"""






          super().__init__(**lowercase__			)

          SCREAMING_SNAKE_CASE_      :			int     =       num_channels
          SCREAMING_SNAKE_CASE_      :			List[str]     =       image_size
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       patch_size
          SCREAMING_SNAKE_CASE_      :			List[str]     =       hidden_sizes
          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       neck_hidden_sizes
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       num_attention_heads
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       mlp_ratio
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       expand_ratio
          SCREAMING_SNAKE_CASE_      :			str     =       hidden_act
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       conv_kernel_size
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       output_stride
          SCREAMING_SNAKE_CASE_      :			Tuple     =       hidden_dropout_prob
          SCREAMING_SNAKE_CASE_      :			int     =       attention_probs_dropout_prob
          SCREAMING_SNAKE_CASE_      :			Tuple     =       classifier_dropout_prob
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       initializer_range
          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       layer_norm_eps
          SCREAMING_SNAKE_CASE_      :			str     =       qkv_bias

          # decode head attributes for semantic segmentation
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       aspp_out_channels
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       atrous_rates
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       aspp_dropout_prob
          SCREAMING_SNAKE_CASE_      :			Any     =       semantic_loss_ignore_index






class 	SCREAMING_SNAKE_CASE__			(				_UpperCAmelCase      ):
    _A			    =							version.parse("1.11"      )




    @property
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return OrderedDict([("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"})]			)




    @property
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          if self.task == "image-classification":
                return OrderedDict([("logits", {0: "batch"})]			)
          else:
                return OrderedDict([("last_hidden_state", {0: "batch"}), ("pooler_output", {0: "batch"})]			)







    @property
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return 1e-4

