

'''simple docstring'''





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


UpperCamelCase_    						=       logging.get_logger(__name__)

UpperCamelCase_    						=       {
    """google/switch-base-8""": """https://huggingface.co/google/switch-base-8/blob/main/config.json""",
}





class 		__SCREAMING_SNAKE_CASE							(			lowercase__      ):
				lowerCamelCase_		       =    'switch_transformers'
				lowerCamelCase_		       =    ['past_key_values']
				lowerCamelCase_		       =    {'hidden_size': 'd_model', 'num_attention_heads': 'num_heads', 'num_hidden_layers': 'num_layers'}







				def __init__(       self     :		Optional[Any]		,					UpperCAmelCase__     :		Any=32128		,					UpperCAmelCase__     :		Optional[Any]=768		,					UpperCAmelCase__     :		Optional[Any]=64		,					UpperCAmelCase__     :		Optional[int]=2048		,					UpperCAmelCase__     :		Dict=64		,					UpperCAmelCase__     :		Any=12		,					UpperCAmelCase__     :		Tuple=3		,					UpperCAmelCase__     :		Dict=12		,					UpperCAmelCase__     :		Any=3		,					UpperCAmelCase__     :		List[Any]=12		,					UpperCAmelCase__     :		Optional[int]=8		,					UpperCAmelCase__     :		Optional[Any]=False		,					UpperCAmelCase__     :		Dict=0.01		,					UpperCAmelCase__     :		str="float32"		,					UpperCAmelCase__     :		str=False		,					UpperCAmelCase__     :		List[str]=32		,					UpperCAmelCase__     :		Tuple=128		,					UpperCAmelCase__     :		Optional[Any]=0.1		,					UpperCAmelCase__     :		str=1E-6		,					UpperCAmelCase__     :		Tuple=0.0_01		,					UpperCAmelCase__     :		int=0.0_01		,					UpperCAmelCase__     :		Any=1.0		,					UpperCAmelCase__     :		Tuple="relu"		,					UpperCAmelCase__     :		int=True		,					UpperCAmelCase__     :		Optional[int]=False		,					UpperCAmelCase__     :		Optional[Any]=True		,					UpperCAmelCase__     :		Any=0		,					UpperCAmelCase__     :		List[Any]=1		,					**UpperCAmelCase__     :		Dict		,					):
										'''simple docstring'''
										lowercase :							Union[str, Any]    		=vocab_size
										lowercase :							Optional[int]    		=d_model
										lowercase :							Optional[int]    		=d_kv
										lowercase :							Optional[Any]    		=d_ff

										lowercase :							List[Any]    		=num_sparse_encoder_layers

										lowercase :							int    		=num_layers
										lowercase :							str    		=(
										    num_decoder_layers if num_decoder_layers is not None else self.num_layers
										)  # default = symmetry
										lowercase :							int    		=num_sparse_decoder_layers

										# This tells us, each how many encoder layer we'll have to set a sparse layer.
										if self.num_sparse_encoder_layers > 0:
																lowercase :							Optional[Any]    		=self.num_layers // self.num_sparse_encoder_layers
										else:
																lowercase :							Optional[int]    		=self.num_layers  # HACK: this will create 0 sparse layers

										# This tells us, each how many encoder layer we'll have to set a sparse layer.
										if self.num_sparse_decoder_layers > 0:
																lowercase :							Optional[Any]    		=self.num_decoder_layers // self.num_sparse_decoder_layers
										else:
																lowercase :							int    		=self.num_decoder_layers  # HACK: this will create 0 sparse layers

										lowercase :							Tuple    		=num_heads
										lowercase :							Optional[int]    		=num_experts
										lowercase :							Optional[int]    		=expert_capacity
										lowercase :							Optional[Any]    		=router_bias
										lowercase :							str    		=router_jitter_noise
										if router_dtype not in ["float32", "float16", "bfloat16"]:
																raise ValueError(F'''`router_dtype` must be one of \'float32\', \'float16\' or \'bfloat16\', got {router_dtype}'''   )
										lowercase :							Dict    		=router_dtype

										lowercase :							Optional[int]    		=router_ignore_padding_tokens
										lowercase :							Any    		=relative_attention_num_buckets
										lowercase :							str    		=relative_attention_max_distance

										lowercase :							str    		=dropout_rate
										lowercase :							Optional[int]    		=layer_norm_epsilon
										lowercase :							Dict    		=initializer_factor
										lowercase :							int    		=feed_forward_proj
										lowercase :							List[Any]    		=use_cache
										lowercase :							List[str]    		=add_router_probs

										lowercase :							Optional[int]    		=router_z_loss_coef
										lowercase :							Optional[int]    		=router_aux_loss_coef

										lowercase :							Optional[Any]    		=self.feed_forward_proj.split('''-'''   )
										lowercase :							Union[str, Any]    		=act_info[-1]
										lowercase :							Optional[int]    		=act_info[0] == '''gated'''

										if len(UpperCAmelCase__   ) > 1 and act_info[0] != "gated" or len(UpperCAmelCase__   ) > 2:
																raise ValueError(
																    F'''`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer.'''
																    '''Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '''
																    '''\'gated-gelu\' or \'relu\''''   )

										# for backwards compatibility
										if feed_forward_proj == "gated-gelu":
																lowercase :							str    		='''gelu_new'''

										super().__init__(
										    pad_token_id=UpperCAmelCase__		,					eos_token_id=UpperCAmelCase__		,					is_encoder_decoder=UpperCAmelCase__		,					**UpperCAmelCase__		,					)












"""simple docstring"""




def  _SCREAMING_SNAKE_CASE						(      _lowercase		:       list[int]   )					->float:






	'''simple docstring'''






	if not nums:  # Makes sure that the list is not empty
		raise ValueError("List is empty"   )

	a :						Dict      =							sum(_lowercase   ) / len(_lowercase   )  # Calculate the average
	return sum(abs(x - average   ) for x in nums   ) / len(_lowercase   )


if __name__ == "__main__":
		import doctest

		doctest.testmod()


