






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


SCREAMING_SNAKE_CASE__     =       logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__     =       {
    '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     a_						(      lowerCamelCase    ):
  lowercase							=				"""levit"""

  def __init__(				self      ,		_SCREAMING_SNAKE_CASE=224      ,		_SCREAMING_SNAKE_CASE=3      ,		_SCREAMING_SNAKE_CASE=3      ,		_SCREAMING_SNAKE_CASE=2      ,		_SCREAMING_SNAKE_CASE=1      ,		_SCREAMING_SNAKE_CASE=16      ,		_SCREAMING_SNAKE_CASE=[128, 256, 384]      ,		_SCREAMING_SNAKE_CASE=[4, 8, 12]      ,		_SCREAMING_SNAKE_CASE=[4, 4, 4]      ,		_SCREAMING_SNAKE_CASE=[16, 16, 16]      ,		_SCREAMING_SNAKE_CASE=0      ,		_SCREAMING_SNAKE_CASE=[2, 2, 2]      ,		_SCREAMING_SNAKE_CASE=[2, 2, 2]      ,		_SCREAMING_SNAKE_CASE=0.0_2      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				Optional[Any]:



        """simple docstring"""






        super().__init__(**_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = image_size
        UpperCamelCase      = num_channels
        UpperCamelCase      = kernel_size
        UpperCamelCase      = stride
        UpperCamelCase      = padding
        UpperCamelCase      = hidden_sizes
        UpperCamelCase      = num_attention_heads
        UpperCamelCase      = depths
        UpperCamelCase      = key_dim
        UpperCamelCase      = drop_path_rate
        UpperCamelCase      = patch_size
        UpperCamelCase      = attention_ratio
        UpperCamelCase      = mlp_ratio
        UpperCamelCase      = initializer_range
        UpperCamelCase      = [
            ["""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     a_						(      lowerCamelCase    ):
  lowercase							=				version.parse("""1.11"""    )

  @property
  def   A__						(				self				)  ->				Mapping[str, Mapping[int, str]]:



        """simple docstring"""






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


  @property
  def   A__						(				self				)  ->				float:



        """simple docstring"""






        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     a_						(      unittest.TestCase    ):

  def   A__						(				self				)  ->				Tuple:



        """simple docstring"""






        UpperCamelCase      = ["""a""", """b""", """c"""]

        # Defaults to last layer if both are None
        UpperCamelCase  ,UpperCamelCase      = 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
        UpperCamelCase  ,UpperCamelCase      = 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
        UpperCamelCase  ,UpperCamelCase      = 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
        UpperCamelCase  ,UpperCamelCase      = 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   A__						(				self				)  ->				str:



        """simple docstring"""






        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   A__						(				self				)  ->				Union[str, Any]:



        """simple docstring"""






        UpperCamelCase      = BackboneMixin()

        UpperCamelCase      = ["""a""", """b""", """c"""]
        UpperCamelCase      = ["""a""", """c"""]
        UpperCamelCase      = [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
        UpperCamelCase      = ["""a""", """b"""]
        self.assertEqual(backbone.out_features      ,		["""a""", """b"""]				)
        self.assertEqual(backbone.out_indices      ,		[0, 1]				)

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