



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


lowerCAmelCase__	    =    logging.get_logger(__name__)

lowerCAmelCase__	    =    {
    '''facebook/levit-128S''': '''https://huggingface.co/facebook/levit-128S/resolve/main/config.json''',
    # See all LeViT models at https://huggingface.co/models?filter=levit
}

class  snake_case__(_lowerCAmelCase     ):

					"""simple docstring"""






					lowercase_								=						"levit"







					def __init__(				self   :      Optional[int] ,  SCREAMING_SNAKE_CASE   :      Optional[int]=224 ,  SCREAMING_SNAKE_CASE   :      Union[str, Any]=3 ,  SCREAMING_SNAKE_CASE   :      List[str]=3 ,  SCREAMING_SNAKE_CASE   :      Tuple=2 ,  SCREAMING_SNAKE_CASE   :      Union[str, Any]=1 ,  SCREAMING_SNAKE_CASE   :      Optional[int]=16 ,  SCREAMING_SNAKE_CASE   :      List[str]=[128, 256, 384] ,  SCREAMING_SNAKE_CASE   :      List[str]=[4, 8, 12] ,  SCREAMING_SNAKE_CASE   :      Optional[Any]=[4, 4, 4] ,  SCREAMING_SNAKE_CASE   :      Tuple=[16, 16, 16] ,  SCREAMING_SNAKE_CASE   :      Union[str, Any]=0 ,  SCREAMING_SNAKE_CASE   :      Tuple=[2, 2, 2] ,  SCREAMING_SNAKE_CASE   :      str=[2, 2, 2] ,  SCREAMING_SNAKE_CASE   :      int=0.02 ,  **SCREAMING_SNAKE_CASE   :      List[str] ,  ):
									super().__init__(**SCREAMING_SNAKE_CASE__	)
									lowercase__	:       Union[str, Any]						=	image_size
									lowercase__	:       List[str]						=	num_channels
									lowercase__	:       Any						=	kernel_size
									lowercase__	:       Union[str, Any]						=	stride
									lowercase__	:       int						=	padding
									lowercase__	:       Union[str, Any]						=	hidden_sizes
									lowercase__	:       Optional[int]						=	num_attention_heads
									lowercase__	:       Dict						=	depths
									lowercase__	:       int						=	key_dim
									lowercase__	:       List[Any]						=	drop_path_rate
									lowercase__	:       Dict						=	patch_size
									lowercase__	:       Optional[Any]						=	attention_ratio
									lowercase__	:       Optional[Any]						=	mlp_ratio
									lowercase__	:       Tuple						=	initializer_range
									lowercase__	:       Optional[Any]						=	[
									    ["Subsample", key_dim[0], hidden_sizes[0] // key_dim[0], 4, 2, 2],
									    ["Subsample", key_dim[0], hidden_sizes[1] // key_dim[0], 4, 2, 2],
									]






class  snake_case__(_lowerCAmelCase     ):

					"""simple docstring"""






					lowercase_								=						version.parse("""1.11"""     )







					@property
					def 					snake_case	(				self   :      Optional[Any]	):
									return OrderedDict(
									    [
									        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
									    ]	)







					@property
					def 					snake_case	(				self   :      List[Any]	):
									return 1E-4









"""simple docstring"""







import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)






class       UpperCamelCase__			(   unittest.TestCase      ):

			"""simple docstring"""


			def   snake_case__	(      self		)      ->	Dict:
				A__											=					["a", "b", "c"]

				# Defaults to last layer if both are None
				A__							,							A__											=					get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	["c"]		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	[2]		)

				# Out indices set to match out features
				A__							,							A__											=					get_aligned_output_features_output_indices(["a", "c"]						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	["a", "c"]		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	[0, 2]		)

				# Out features set to match out indices
				A__							,							A__											=					get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__						,	[0, 2]						,	SCREAMING_SNAKE_CASE__		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	["a", "c"]		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	[0, 2]		)

				# Out features selected from negative indices
				A__							,							A__											=					get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__						,	[-3, -1]						,	SCREAMING_SNAKE_CASE__		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	["a", "c"]		)
				self.assertEqual(SCREAMING_SNAKE_CASE__						,	[-3, -1]		)


			def   snake_case__	(      self		)      ->	Dict:
				# Stage names must be set
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(["a", "b"]						,	(0, 1)						,	SCREAMING_SNAKE_CASE__		)

				# Out features must be a list
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(("a", "b")						,	(0, 1)						,	["a", "b"]		)

				# Out features must be a subset of stage names
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(["a", "b"]						,	(0, 1)						,	["a"]		)

				# Out indices must be a list or tuple
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(SCREAMING_SNAKE_CASE__						,	0						,	["a", "b"]		)

				# Out indices must be a subset of stage names
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(SCREAMING_SNAKE_CASE__						,	(0, 1)						,	["a"]		)

				# Out features and out indices must be the same length
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(["a", "b"]						,	(0,)						,	["a", "b", "c"]		)

				# Out features should match out indices
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(["a", "b"]						,	(0, 2)						,	["a", "b", "c"]		)

				# Out features and out indices should be in order
				with self.assertRaises(SCREAMING_SNAKE_CASE__		):
					verify_out_features_out_indices(["b", "a"]						,	(0, 1)						,	["a", "b"]		)

				# Check passes with valid inputs
				verify_out_features_out_indices(["a", "b", "d"]						,	(0, 1, -1)						,	["a", "b", "c", "d"]		)







			def   snake_case__	(      self		)      ->	List[Any]:
				A__											=					BackboneMixin()

				A__											=					["a", "b", "c"]
				A__											=					["a", "c"]
				A__											=					[0, 2]

				# Check that the output features and indices are set correctly
				self.assertEqual(backbone.out_features						,	["a", "c"]		)
				self.assertEqual(backbone.out_indices						,	[0, 2]		)

				# Check out features and indices are updated correctly
				A__											=					["a", "b"]
				self.assertEqual(backbone.out_features						,	["a", "b"]		)
				self.assertEqual(backbone.out_indices						,	[0, 1]		)

				A__											=					[-3, -1]
				self.assertEqual(backbone.out_features						,	["a", "c"]		)
				self.assertEqual(backbone.out_indices						,	[-3, -1]		)




