






from typing import List

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


SCREAMING_SNAKE_CASE__   :      List[str]				=		logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__   :      int				=		{
    """snap-research/efficientformer-l1-300""": (
        """https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json"""
    ),
}
class     lowerCamelCase_					(   lowerCamelCase			):
				a__       							=	'''efficientformer'''







				def __init__(    self							,       __lowerCAmelCase = [3, 2, 6, 4]							,       __lowerCAmelCase = [4_8, 9_6, 2_2_4, 4_4_8]							,       __lowerCAmelCase = [True, True, True, True]							,       __lowerCAmelCase = 4_4_8							,       __lowerCAmelCase = 3_2							,       __lowerCAmelCase = 4							,       __lowerCAmelCase = 7							,       __lowerCAmelCase = 5							,       __lowerCAmelCase = 8							,       __lowerCAmelCase = 4							,       __lowerCAmelCase = 0.0							,       __lowerCAmelCase = 1_6							,       __lowerCAmelCase = 3							,       __lowerCAmelCase = 3							,       __lowerCAmelCase = 3							,       __lowerCAmelCase = 2							,       __lowerCAmelCase = 1							,       __lowerCAmelCase = 0.0							,       __lowerCAmelCase = 1							,       __lowerCAmelCase = True							,       __lowerCAmelCase = True							,       __lowerCAmelCase = 1E-5							,       __lowerCAmelCase = "gelu"							,       __lowerCAmelCase = 0.02							,       __lowerCAmelCase = 1E-12							,       __lowerCAmelCase = 2_2_4							,       __lowerCAmelCase = 1E-05							,       **__lowerCAmelCase							,       ):
								"""simple docstring"""
								super().__init__(**__lowerCAmelCase  )

								__magic_name__		:Union[str, Any]   =   hidden_act
								__magic_name__		:int   =   hidden_dropout_prob
								__magic_name__		:List[Any]   =   hidden_sizes
								__magic_name__		:Optional[Any]   =   num_hidden_layers
								__magic_name__		:str   =   num_attention_heads
								__magic_name__		:int   =   initializer_range
								__magic_name__		:Optional[Any]   =   layer_norm_eps
								__magic_name__		:Optional[Any]   =   patch_size
								__magic_name__		:int   =   num_channels
								__magic_name__		:Optional[int]   =   depths
								__magic_name__		:List[Any]   =   mlp_expansion_ratio
								__magic_name__		:int   =   downsamples
								__magic_name__		:Dict   =   dim
								__magic_name__		:List[Any]   =   key_dim
								__magic_name__		:List[Any]   =   attention_ratio
								__magic_name__		:str   =   resolution
								__magic_name__		:Optional[int]   =   pool_size
								__magic_name__		:List[Any]   =   downsample_patch_size
								__magic_name__		:int   =   downsample_stride
								__magic_name__		:Any   =   downsample_pad
								__magic_name__		:Optional[Any]   =   drop_path_rate
								__magic_name__		:List[str]   =   num_metaad_blocks
								__magic_name__		:Any   =   distillation
								__magic_name__		:Tuple   =   use_layer_scale
								__magic_name__		:Dict   =   layer_scale_init_value
								__magic_name__		:List[Any]   =   image_size
								__magic_name__		:Optional[Any]   =   batch_norm_eps








from math import ceil






def   lowerCamelCase__							(							__lowerCAmelCase    :    Dict       ,				__lowerCAmelCase    :    int							):




			"""simple docstring"""


			lowerCAmelCase_         =      list(range(0       ,				__lowerCAmelCase							)							)

			lowerCAmelCase_         =      [item for sublist in list(device_map.values()							) for item in sublist]

			# Duplicate check
			lowerCAmelCase_         =      []
			for i in device_map_blocks:
						if device_map_blocks.count(__lowerCAmelCase							) > 1 and i not in duplicate_blocks:
									duplicate_blocks.append(__lowerCAmelCase							)
    # Missing blocks
			lowerCAmelCase_         =      [i for i in blocks if i not in device_map_blocks]
			lowerCAmelCase_         =      [i for i in device_map_blocks if i not in blocks]

			if len(__lowerCAmelCase							) != 0:
						raise ValueError(
						    "Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device."
						    " These attention blocks were specified more than once: " + str(__lowerCAmelCase							)							)
			if len(__lowerCAmelCase							) != 0:
						raise ValueError(
						    "There are attention blocks for this model that are not specified in the device_map. Add these attention "
						    "blocks to a device on the device_map: " + str(__lowerCAmelCase							)							)
			if len(__lowerCAmelCase							) != 0:
						raise ValueError(
						    "The device_map contains more attention blocks than this model has. Remove these from the device_map:"
						    + str(__lowerCAmelCase							)							)






def   lowerCamelCase__							(							__lowerCAmelCase    :    List[str]       ,				__lowerCAmelCase    :    Tuple							):




			"""simple docstring"""


			lowerCAmelCase_         =      list(range(__lowerCAmelCase							)							)
			lowerCAmelCase_         =      int(ceil(n_layers / len(__lowerCAmelCase							)							)							)
			lowerCAmelCase_         =      [layers[i : i + n_blocks] for i in range(0       ,				__lowerCAmelCase       ,				__lowerCAmelCase							)]

			return dict(zip(__lowerCAmelCase       ,				__lowerCAmelCase							)							)



