


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


_SCREAMING_SNAKE_CASE     :					Union[str, Any]      =       logging.get_logger(__name__)

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

class     A__   (       snake_case__      ):







    """simple docstring"""

    __magic_name__         =						'switch_transformers'
    __magic_name__         =						['past_key_values']
    __magic_name__         =						{'hidden_size': 'd_model', 'num_attention_heads': 'num_heads', 'num_hidden_layers': 'num_layers'}
    def __init__(			self     ,   __snake_case=3_2_1_2_8     ,   __snake_case=7_6_8     ,   __snake_case=6_4     ,   __snake_case=2_0_4_8     ,   __snake_case=6_4     ,   __snake_case=1_2     ,   __snake_case=3     ,   __snake_case=1_2     ,   __snake_case=3     ,   __snake_case=1_2     ,   __snake_case=8     ,   __snake_case=False     ,   __snake_case=0.01     ,   __snake_case="float32"     ,   __snake_case=False     ,   __snake_case=3_2     ,   __snake_case=1_2_8     ,   __snake_case=0.1     ,   __snake_case=1E-6     ,   __snake_case=0.001     ,   __snake_case=0.001     ,   __snake_case=1.0     ,   __snake_case="relu"     ,   __snake_case=True     ,   __snake_case=False     ,   __snake_case=True     ,   __snake_case=0     ,   __snake_case=1     ,   **__snake_case     ,   ):
         snake_case											=							vocab_size
         snake_case											=							d_model
         snake_case											=							d_kv
         snake_case											=							d_ff

         snake_case											=							num_sparse_encoder_layers

         snake_case											=							num_layers
         snake_case											=							(
             num_decoder_layers if num_decoder_layers is not None else self.num_layers
         )  # default = symmetry
         snake_case											=							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:
              snake_case											=							self.num_layers // self.num_sparse_encoder_layers
         else:
              snake_case											=							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:
              snake_case											=							self.num_decoder_layers // self.num_sparse_decoder_layers
         else:
              snake_case											=							self.num_decoder_layers  # HACK: this will create 0 sparse layers

         snake_case											=							num_heads
         snake_case											=							num_experts
         snake_case											=							expert_capacity
         snake_case											=							router_bias
         snake_case											=							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}'''       )
         snake_case											=							router_dtype

         snake_case											=							router_ignore_padding_tokens
         snake_case											=							relative_attention_num_buckets
         snake_case											=							relative_attention_max_distance

         snake_case											=							dropout_rate
         snake_case											=							layer_norm_epsilon
         snake_case											=							initializer_factor
         snake_case											=							feed_forward_proj
         snake_case											=							use_cache
         snake_case											=							add_router_probs

         snake_case											=							router_z_loss_coef
         snake_case											=							router_aux_loss_coef

         snake_case											=							self.feed_forward_proj.split('''-'''       )
         snake_case											=							act_info[-1]
         snake_case											=							act_info[0] == '''gated'''

         if len(__snake_case       ) > 1 and act_info[0] != "gated" or len(__snake_case       ) > 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":
              snake_case											=							'''gelu_new'''

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








import os
from distutils.util import strtobool
def      UpperCAmelCase__		(UpperCamelCase_				,UpperCamelCase_							):



     """simple docstring"""






     for e in env_keys:
          snake_case											=							int(os.environ.get(UpperCamelCase_				,-1							)							)
          if val >= 0:
               return val
     return default
def      UpperCAmelCase__		(UpperCamelCase_				,UpperCamelCase_=False							):



     """simple docstring"""






     snake_case											=							os.environ.get(UpperCamelCase_				,str(UpperCamelCase_							)							)
     return strtobool(UpperCamelCase_							) == 1  # As its name indicates `strtobool` actually returns an int...

def      UpperCAmelCase__		(UpperCamelCase_				,UpperCamelCase_="no"							):



     """simple docstring"""






     snake_case											=							os.environ.get(UpperCamelCase_				,str(UpperCamelCase_							)							)
     return value




