


"""simple docstring"""







from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

a__    :							Tuple            =					TypeVar('''T''')
a__    :							int            =					TypeVar('''U''')




class 			UpperCamelCase_     (			Generic[T, U]):

	"""simple docstring"""





	def __init__(			self      :    List[Any]      ,      UpperCAmelCase__      :    T | None      ,      UpperCAmelCase__      :    U | None       )	->     Dict:
							__SCREAMING_SNAKE_CASE						       =    key
							__SCREAMING_SNAKE_CASE						       =    val
							__SCREAMING_SNAKE_CASE						       =    None
							__SCREAMING_SNAKE_CASE						       =    None




	def __repr__(			self      :    Optional[Any]       )	->     str:
							return (
							    F"""Node: key: {self.key}, val: {self.val}, """
							    F"""has next: {bool(self.next       )}, has prev: {bool(self.prev       )}"""
							)




class 			UpperCamelCase_     (			Generic[T, U]):

	"""simple docstring"""





	def __init__(			self      :    str       )	->     None:
							__SCREAMING_SNAKE_CASE						       =    DoubleLinkedListNode(UpperCAmelCase__      ,      UpperCAmelCase__       )
							__SCREAMING_SNAKE_CASE						       =    DoubleLinkedListNode(UpperCAmelCase__      ,      UpperCAmelCase__       )
							__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    self.rear, self.head




	def __repr__(			self      :    Optional[Any]       )	->     str:
							__SCREAMING_SNAKE_CASE						       =    ["DoubleLinkedList"]
							__SCREAMING_SNAKE_CASE						       =    self.head
							while node.next is not None:
													rep.append(str(UpperCAmelCase__       )       )
													__SCREAMING_SNAKE_CASE						       =    node.next
							rep.append(str(self.rear       )       )
							return ",\n    ".join(UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]      ,      UpperCAmelCase__      :    DoubleLinkedListNode[T, U]       )	->     None:
							__SCREAMING_SNAKE_CASE						       =    self.rear.prev

							# All nodes other than self.head are guaranteed to have non-None previous
							assert previous is not None

							__SCREAMING_SNAKE_CASE						       =    node
							__SCREAMING_SNAKE_CASE						       =    previous
							__SCREAMING_SNAKE_CASE						       =    node
							__SCREAMING_SNAKE_CASE						       =    self.rear




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    DoubleLinkedListNode[T, U]       )	->     DoubleLinkedListNode[T, U] | None:

							if node.prev is None or node.next is None:
													return None

							__SCREAMING_SNAKE_CASE						       =    node.next
							__SCREAMING_SNAKE_CASE						       =    node.prev
							__SCREAMING_SNAKE_CASE						       =    None
							__SCREAMING_SNAKE_CASE						       =    None
							return node




class 			UpperCamelCase_     (			Generic[T, U]):

	"""simple docstring"""





	snake_case__    :  dict[Callable[[T], U], LRUCache[T, U]]    =      {}




	def __init__(			self      :    Any      ,      UpperCAmelCase__      :    int       )	->     Union[str, Any]:
							__SCREAMING_SNAKE_CASE						       =    DoubleLinkedList()
							__SCREAMING_SNAKE_CASE						       =    capacity
							__SCREAMING_SNAKE_CASE						       =    0
							__SCREAMING_SNAKE_CASE						       =    0
							__SCREAMING_SNAKE_CASE						       =    0
							__SCREAMING_SNAKE_CASE						       =    {}




	def __repr__(			self      :    List[str]       )	->     str:
							return (
							    F"""CacheInfo(hits={self.hits}, misses={self.miss}, """
							    F"""capacity={self.capacity}, current size={self.num_keys})"""
							)




	def __contains__(			self      :    Tuple      ,      UpperCAmelCase__      :    T       )	->     bool:
							return key in self.cache




	def   UpperCAmelCase_				(			self      :    List[str]      ,      UpperCAmelCase__      :    T       )	->     U | None:
							# Note: pythonic interface would throw KeyError rather than return None

							if key in self.cache:
													self.hits += 1
													__SCREAMING_SNAKE_CASE						       =    self.cache[key]
													__SCREAMING_SNAKE_CASE						       =    self.list.remove(self.cache[key]       )
													assert node == value_node

													# node is guaranteed not None because it is in self.cache
													assert node is not None
													self.list.add(UpperCAmelCase__       )
													return node.val
							self.miss += 1
							return None




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    T      ,      UpperCAmelCase__      :    U       )	->     None:

							if key not in self.cache:
													if self.num_keys >= self.capacity:
																			# delete first node (oldest) when over capacity
																			__SCREAMING_SNAKE_CASE						       =    self.list.head.next

																			# guaranteed to have a non-None first node when num_keys > 0
																			# explain to type checker via assertions
																			assert first_node is not None
																			assert first_node.key is not None
																			assert (
																			    self.list.remove(UpperCAmelCase__       ) is not None
																			)  # node guaranteed to be in list assert node.key is not None

																			del self.cache[first_node.key]
																			self.num_keys -= 1
													__SCREAMING_SNAKE_CASE						       =    DoubleLinkedListNode(UpperCAmelCase__      ,      UpperCAmelCase__       )
													self.list.add(self.cache[key]       )
													self.num_keys += 1

							else:
													# bump node to the end of the list, update value
													__SCREAMING_SNAKE_CASE						       =    self.list.remove(self.cache[key]       )
													assert node is not None  # node guaranteed to be in list
													__SCREAMING_SNAKE_CASE						       =    value
													self.list.add(UpperCAmelCase__       )




	@classmethod
	def   UpperCAmelCase_				(			cls      :    Union[str, Any]      ,      UpperCAmelCase__      :    int = 1_2_8       )	->     Callable[[Callable[[T], U]], Callable[..., U]]:

							def cache_decorator_inner(UpperCAmelCase__      :    Callable[[T], U]       ) -> Callable[..., U]:
													def cache_decorator_wrapper(*UpperCAmelCase__      :    T       ) -> U:
																			if func not in cls.decorator_function_to_instance_map:
																									__SCREAMING_SNAKE_CASE						       =    LRUCache(UpperCAmelCase__       )

																			__SCREAMING_SNAKE_CASE						       =    cls.decorator_function_to_instance_map[func].get(args[0]       )
																			if result is None:
																									__SCREAMING_SNAKE_CASE						       =    func(*UpperCAmelCase__       )
																									cls.decorator_function_to_instance_map[func].put(args[0]      ,      UpperCAmelCase__       )
																			return result

													def cache_info() -> LRUCache[T, U]:
																			return cls.decorator_function_to_instance_map[func]

													setattr(UpperCAmelCase__      ,      "cache_info"      ,      UpperCAmelCase__       )  # noqa: B010

													return cache_decorator_wrapper

							return cache_decorator_inner


if __name__ == "__main__":
		import doctest

		doctest.testmod()




"""simple docstring"""







from typing import List

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a__    :							Tuple            =					logging.get_logger(__name__)

a__    :							List[Any]            =					{
    '''snap-research/efficientformer-l1-300''': (
        '''https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json'''
    ),
}




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	snake_case__    :  Any    =      "efficientformer"




	def __init__(			self      :    Any      ,      UpperCAmelCase__      :    List[int] = [3, 2, 6, 4]      ,      UpperCAmelCase__      :    List[int] = [4_8, 9_6, 2_2_4, 4_4_8]      ,      UpperCAmelCase__      :    List[bool] = [True, True, True, True]      ,      UpperCAmelCase__      :    int = 4_4_8      ,      UpperCAmelCase__      :    int = 3_2      ,      UpperCAmelCase__      :    int = 4      ,      UpperCAmelCase__      :    int = 7      ,      UpperCAmelCase__      :    int = 5      ,      UpperCAmelCase__      :    int = 8      ,      UpperCAmelCase__      :    int = 4      ,      UpperCAmelCase__      :    float = 0.0      ,      UpperCAmelCase__      :    int = 1_6      ,      UpperCAmelCase__      :    int = 3      ,      UpperCAmelCase__      :    int = 3      ,      UpperCAmelCase__      :    int = 3      ,      UpperCAmelCase__      :    int = 2      ,      UpperCAmelCase__      :    int = 1      ,      UpperCAmelCase__      :    float = 0.0      ,      UpperCAmelCase__      :    int = 1      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    bool = True      ,      UpperCAmelCase__      :    float = 1E-5      ,      UpperCAmelCase__      :    str = "gelu"      ,      UpperCAmelCase__      :    float = 0.02      ,      UpperCAmelCase__      :    float = 1E-12      ,      UpperCAmelCase__      :    int = 2_2_4      ,      UpperCAmelCase__      :    float = 1E-05      ,      **UpperCAmelCase__      :    Tuple      ,      )	->     None:
						super().__init__(**UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    hidden_act
						__SCREAMING_SNAKE_CASE						       =    hidden_dropout_prob
						__SCREAMING_SNAKE_CASE						       =    hidden_sizes
						__SCREAMING_SNAKE_CASE						       =    num_hidden_layers
						__SCREAMING_SNAKE_CASE						       =    num_attention_heads
						__SCREAMING_SNAKE_CASE						       =    initializer_range
						__SCREAMING_SNAKE_CASE						       =    layer_norm_eps
						__SCREAMING_SNAKE_CASE						       =    patch_size
						__SCREAMING_SNAKE_CASE						       =    num_channels
						__SCREAMING_SNAKE_CASE						       =    depths
						__SCREAMING_SNAKE_CASE						       =    mlp_expansion_ratio
						__SCREAMING_SNAKE_CASE						       =    downsamples
						__SCREAMING_SNAKE_CASE						       =    dim
						__SCREAMING_SNAKE_CASE						       =    key_dim
						__SCREAMING_SNAKE_CASE						       =    attention_ratio
						__SCREAMING_SNAKE_CASE						       =    resolution
						__SCREAMING_SNAKE_CASE						       =    pool_size
						__SCREAMING_SNAKE_CASE						       =    downsample_patch_size
						__SCREAMING_SNAKE_CASE						       =    downsample_stride
						__SCREAMING_SNAKE_CASE						       =    downsample_pad
						__SCREAMING_SNAKE_CASE						       =    drop_path_rate
						__SCREAMING_SNAKE_CASE						       =    num_metaad_blocks
						__SCREAMING_SNAKE_CASE						       =    distillation
						__SCREAMING_SNAKE_CASE						       =    use_layer_scale
						__SCREAMING_SNAKE_CASE						       =    layer_scale_init_value
						__SCREAMING_SNAKE_CASE						       =    image_size
						__SCREAMING_SNAKE_CASE						       =    batch_norm_eps
