

'''simple docstring'''






from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
      import torch

snake_case_       =       logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
      from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):


      def 					__lowerCamelCase			(      cls     :	List[str]    )							->   List[Any]:
            """simple docstring"""

            return cls


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Union[Tuple, List]  ,  SCREAMING_SNAKE_CASE_     :	Optional[Union[List["torch.Generator"], "torch.Generator"]] = None  ,  SCREAMING_SNAKE_CASE_     :	Optional["torch.device"] = None  ,  SCREAMING_SNAKE_CASE_     :	Optional["torch.dtype"] = None  ,  SCREAMING_SNAKE_CASE_     :	Optional["torch.layout"] = None  ,  )							->   List[Any]:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			List[Any]     =       device
      SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       shape[0]

      SCREAMING_SNAKE_CASE_      :			Tuple     =       layout or torch.strided
      SCREAMING_SNAKE_CASE_      :			Tuple     =       device or torch.device("cpu"    )

      if generator is not None:
            SCREAMING_SNAKE_CASE_      :			Optional[int]     =       generator.device.type if not isinstance(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    ) else generator[0].device.type
            if gen_device_type != device.type and gen_device_type == "cpu":
                  SCREAMING_SNAKE_CASE_      :			List[str]     =       "cpu"
                  if device != "mps":
                        logger.info(
                            F"The passed generator was created on 'cpu' even though a tensor on {device} was expected."
                            F" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"
                            F" slighly speed up this function by passing a generator that was created on the {device} device."    )
            elif gen_device_type != device.type and gen_device_type == "cuda":
                  raise ValueError(F"Cannot generate a {device} tensor from a generator of type {gen_device_type}."    )

      if isinstance(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    ):
            SCREAMING_SNAKE_CASE_      :			List[Any]     =       (1,) + shape[1:]
            SCREAMING_SNAKE_CASE_      :			str     =       [
                torch.randn(SCREAMING_SNAKE_CASE_  ,  generator=generator[i]  ,  device=SCREAMING_SNAKE_CASE_  ,  dtype=SCREAMING_SNAKE_CASE_  ,  layout=SCREAMING_SNAKE_CASE_    )
                for i in range(SCREAMING_SNAKE_CASE_    )
            ]
            SCREAMING_SNAKE_CASE_      :			str     =       torch.cat(SCREAMING_SNAKE_CASE_  ,  dim=0    ).to(SCREAMING_SNAKE_CASE_    )
      else:
            SCREAMING_SNAKE_CASE_      :			Tuple     =       torch.randn(SCREAMING_SNAKE_CASE_  ,  generator=SCREAMING_SNAKE_CASE_  ,  device=SCREAMING_SNAKE_CASE_  ,  dtype=SCREAMING_SNAKE_CASE_  ,  layout=SCREAMING_SNAKE_CASE_    ).to(SCREAMING_SNAKE_CASE_    )

      return latents





def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	str    )							->   str:
      """simple docstring"""

      if is_torch_version("<"  ,  "2.0.0"    ) or not hasattr(SCREAMING_SNAKE_CASE_  ,  "_dynamo"    ):
            return False
      return isinstance(SCREAMING_SNAKE_CASE_  ,  torch._dynamo.eval_frame.OptimizedModule    )




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

