




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


UpperCAmelCase_		:					Any          =  logging.get_logger(__name__)

UpperCAmelCase_		:					Tuple          =  {
    "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   (      UpperCamelCase__      ):
						UpperCamelCase      =       """levit"""

						def __init__(		self :Optional[int]     ,			__snake_case :str=2_24     ,			__snake_case :Any=3     ,			__snake_case :List[str]=3     ,			__snake_case :List[Any]=2     ,			__snake_case :Optional[Any]=1     ,			__snake_case :Optional[int]=16     ,			__snake_case :List[str]=[1_28, 2_56, 3_84]     ,			__snake_case :Dict=[4, 8, 12]     ,			__snake_case :Optional[Any]=[4, 4, 4]     ,			__snake_case :Union[str, Any]=[16, 16, 16]     ,			__snake_case :Any=0     ,			__snake_case :Dict=[2, 2, 2]     ,			__snake_case :List[Any]=[2, 2, 2]     ,			__snake_case :List[Any]=0.02     ,			**__snake_case :Optional[int]     ,			):
										'''simple docstring'''

										super().__init__(**__snake_case			)
										__magic_name__						:						List[Any]										=image_size
										__magic_name__						:						Optional[int]										=num_channels
										__magic_name__						:						Any										=kernel_size
										__magic_name__						:						Optional[Any]										=stride
										__magic_name__						:						Union[str, Any]										=padding
										__magic_name__						:						Tuple										=hidden_sizes
										__magic_name__						:						str										=num_attention_heads
										__magic_name__						:						Dict										=depths
										__magic_name__						:						Union[str, Any]										=key_dim
										__magic_name__						:						int										=drop_path_rate
										__magic_name__						:						List[Any]										=patch_size
										__magic_name__						:						Dict										=attention_ratio
										__magic_name__						:						List[Any]										=mlp_ratio
										__magic_name__						:						Tuple										=initializer_range
										__magic_name__						:						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 		__A   (      UpperCamelCase__      ):
						UpperCamelCase      =       version.parse("""1.11"""      )

						@property
						def      A__    (		self :Optional[int]			):
										'''simple docstring'''

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


						@property
						def      A__    (		self :List[str]			):
										'''simple docstring'''

										return 1E-4










import math

import tensorflow as tf
from packaging import version




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						str										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						List[str]										=0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0 )						,  x.dtype ) ))

				return x * cdf




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						str										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						Optional[Any]										=tf.cast(math.pi						,  x.dtype )
				__magic_name__						:						int										=tf.cast(0.0_4_4_7_1_5						,  x.dtype )
				__magic_name__						:						Tuple										=0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi ) * (x + coeff * tf.pow(lowerCamelCase						,  3 )) ))

				return x * cdf




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						Any										=tf.convert_to_tensor(lowerCamelCase )

				return x * tf.tanh(tf.math.softplus(lowerCamelCase ) )




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						Optional[Any]										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						Union[str, Any]										=tf.cast(0.0_4_4_7_1_5						,  x.dtype )
				__magic_name__						:						Tuple										=tf.cast(0.7_9_7_8_8_4_5_6_0_8						,  x.dtype )

				return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x) ))




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						List[str]										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						Dict										=tf.cast(1.7_0_2						,  x.dtype )
				return x * tf.math.sigmoid(coeff * x )




def 		lowerCAmelCase_ (						lowerCamelCase ):
				return tf.clip_by_value(_gelu(lowerCamelCase )						,  -10						,  10 )




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase=-1 ):
				__magic_name__					,			__magic_name__						:						List[Any]										=tf.split(lowerCamelCase						,  2						,  axis=lowerCamelCase )
				return a * tf.math.sigmoid(lowerCamelCase )


if version.parse(tf.version.VERSION) >= version.parse("2.4"):




							def 		lowerCAmelCase_ (						lowerCamelCase ):
											return tf.keras.activations.gelu(lowerCamelCase						,  approximate=lowerCamelCase )

							UpperCAmelCase_		:					List[str]          =  tf.keras.activations.gelu



							UpperCAmelCase_		:					Dict          =  approximate_gelu_wrap
else:
							UpperCAmelCase_		:					Dict          =  _gelu
							UpperCAmelCase_		:					str          =  _gelu_new


UpperCAmelCase_		:					Any          =  {
    "gelu": gelu,
    "gelu_10": gelu_aa,
    "gelu_fast": gelu_fast,
    "gelu_new": gelu_new,
    "glu": glu,
    "mish": mish,
    "quick_gelu": quick_gelu,
    "relu": tf.keras.activations.relu,
    "sigmoid": tf.keras.activations.sigmoid,
    "silu": tf.keras.activations.swish,
    "swish": tf.keras.activations.swish,
    "tanh": tf.keras.activations.tanh,
}




def 		lowerCAmelCase_ (						lowerCamelCase ):
				if activation_string in ACTaFN:
								return ACTaFN[activation_string]
				else:
								raise KeyError(F"function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys() )}" )




