


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


SCREAMING_SNAKE_CASE       :		List[Any]         =				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE       :		Optional[int]         =				{
    "google/switch-base-8": "https://huggingface.co/google/switch-base-8/blob/main/config.json",
}






class 							UpperCamelCase					(		lowercase__     ):


   '''simple docstring'''







   lowercase					:	Dict									="""switch_transformers"""
   lowercase					:	Dict									=["""past_key_values"""]
   lowercase					:	Optional[Any]									={"""hidden_size""": """d_model""", """num_attention_heads""": """num_heads""", """num_hidden_layers""": """num_layers"""}
   def __init__(     self   ,							UpperCamelCase_=3_2128   ,							UpperCamelCase_=768   ,							UpperCamelCase_=64   ,							UpperCamelCase_=2048   ,							UpperCamelCase_=64   ,							UpperCamelCase_=12   ,							UpperCamelCase_=3   ,							UpperCamelCase_=12   ,							UpperCamelCase_=3   ,							UpperCamelCase_=12   ,							UpperCamelCase_=8   ,							UpperCamelCase_=False   ,							UpperCamelCase_=0.01   ,							UpperCamelCase_="float32"   ,							UpperCamelCase_=False   ,							UpperCamelCase_=32   ,							UpperCamelCase_=128   ,							UpperCamelCase_=0.1   ,							UpperCamelCase_=1E-6   ,							UpperCamelCase_=0.001   ,							UpperCamelCase_=0.001   ,							UpperCamelCase_=1.0   ,							UpperCamelCase_="relu"   ,							UpperCamelCase_=True   ,							UpperCamelCase_=False   ,							UpperCamelCase_=True   ,							UpperCamelCase_=0   ,							UpperCamelCase_=1   ,							**UpperCamelCase_   ,							):
        lowercase_       :Any     =       vocab_size
        lowercase_       :Optional[Any]     =       d_model
        lowercase_       :str     =       d_kv
        lowercase_       :Optional[Any]     =       d_ff

        lowercase_       :Union[str, Any]     =       num_sparse_encoder_layers

        lowercase_       :Union[str, Any]     =       num_layers
        lowercase_       :Union[str, Any]     =       (
            num_decoder_layers if num_decoder_layers is not None else self.num_layers
        )  # default = symmetry
        lowercase_       :str     =       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_       :Dict     =       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_       :int     =       self.num_decoder_layers // self.num_sparse_decoder_layers
        else:
             lowercase_       :Union[str, Any]     =       self.num_decoder_layers  # HACK: this will create 0 sparse layers

        lowercase_       :List[Any]     =       num_heads
        lowercase_       :Dict     =       num_experts
        lowercase_       :Optional[Any]     =       expert_capacity
        lowercase_       :Tuple     =       router_bias
        lowercase_       :Union[str, Any]     =       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_       :Optional[Any]     =       router_dtype

        lowercase_       :int     =       router_ignore_padding_tokens
        lowercase_       :Optional[Any]     =       relative_attention_num_buckets
        lowercase_       :Dict     =       relative_attention_max_distance

        lowercase_       :str     =       dropout_rate
        lowercase_       :List[str]     =       layer_norm_epsilon
        lowercase_       :Optional[int]     =       initializer_factor
        lowercase_       :Tuple     =       feed_forward_proj
        lowercase_       :int     =       use_cache
        lowercase_       :Optional[Any]     =       add_router_probs

        lowercase_       :List[Any]     =       router_z_loss_coef
        lowercase_       :str     =       router_aux_loss_coef

        lowercase_       :Optional[Any]     =       self.feed_forward_proj.split('''-'''		)
        lowercase_       :Optional[Any]     =       act_info[-1]
        lowercase_       :Tuple     =       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_       :int     =       '''gelu_new'''

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





from torch import nn




def     UpperCamelCase    (      _a		)					->							str:
     '''simple docstring'''





     if act_fn in ["swish", "silu"]:
          return nn.SiLU()
     elif act_fn == "mish":
          return nn.Mish()
     elif act_fn == "gelu":
          return nn.GELU()
     else:
          raise ValueError(f"Unsupported activation function: {act_fn}"		)

