





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


_lowercase		:				Dict      		=logging.get_logger(__name__)

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

class        snake_case__    (a_		):







						"""simple docstring"""




						__lowerCAmelCase					:Tuple      =					"switch_transformers"
						__lowerCAmelCase					:Tuple      =					["past_key_values"]
						__lowerCAmelCase					:Any      =					{"hidden_size": "d_model", "num_attention_heads": "num_heads", "num_hidden_layers": "num_layers"}

						def __init__(       self ,       __lowercase=3_2_1_2_8 ,       __lowercase=7_6_8 ,       __lowercase=6_4 ,       __lowercase=2_0_4_8 ,       __lowercase=6_4 ,       __lowercase=1_2 ,       __lowercase=3 ,       __lowercase=1_2 ,       __lowercase=3 ,       __lowercase=1_2 ,       __lowercase=8 ,       __lowercase=False ,       __lowercase=0.0_1 ,       __lowercase="float32" ,       __lowercase=False ,       __lowercase=3_2 ,       __lowercase=1_2_8 ,       __lowercase=0.1 ,       __lowercase=1E-6 ,       __lowercase=0.0_0_1 ,       __lowercase=0.0_0_1 ,       __lowercase=1.0 ,       __lowercase="relu" ,       __lowercase=True ,       __lowercase=False ,       __lowercase=True ,       __lowercase=0 ,       __lowercase=1 ,       **__lowercase ,       ) ->				str:
									"""simple docstring"""




									a__       :						Union[str, Any]							=  vocab_size
									a__       :						Dict							=  d_model
									a__       :						Optional[int]							=  d_kv
									a__       :						List[str]							=  d_ff

									a__       :						str							=  num_sparse_encoder_layers

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

									a__       :						Any							=  num_heads
									a__       :						Any							=  num_experts
									a__       :						Optional[int]							=  expert_capacity
									a__       :						int							=  router_bias
									a__       :						Optional[int]							=  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}'''  )
									a__       :						int							=  router_dtype

									a__       :						Any							=  router_ignore_padding_tokens
									a__       :						Union[str, Any]							=  relative_attention_num_buckets
									a__       :						Dict							=  relative_attention_max_distance

									a__       :						Any							=  dropout_rate
									a__       :						int							=  layer_norm_epsilon
									a__       :						Optional[Any]							=  initializer_factor
									a__       :						int							=  feed_forward_proj
									a__       :						Optional[Any]							=  use_cache
									a__       :						Dict							=  add_router_probs

									a__       :						Optional[int]							=  router_z_loss_coef
									a__       :						Union[str, Any]							=  router_aux_loss_coef

									a__       :						List[str]							=  self.feed_forward_proj.split("""-"""  )
									a__       :						Tuple							=  act_info[-1]
									a__       :						int							=  act_info[0] == """gated"""

									if len(__lowercase  ) > 1 and act_info[0] != "gated" or len(__lowercase  ) > 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":
												a__       :						List[str]							=  """gelu_new"""

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









import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
		import ctypes
		import msvcrt  # noqa

		class        snake_case__    (ctypes.Structure		):







								"""simple docstring"""




								__lowerCAmelCase					:Dict      =					[("size", ctypes.c_int), ("visible", ctypes.c_byte)]

def      lowerCAmelCase_					(  )							->	List[Any]:







			"""simple docstring"""
			if os.name == "nt":
						a__       :						int							=  CursorInfo()
						a__       :						Union[str, Any]							=  ctypes.windll.kernelaa.GetStdHandle(-11)
						ctypes.windll.kernelaa.GetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
						a__       :						List[str]							=  False
						ctypes.windll.kernelaa.SetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
			elif os.name == "posix":
						sys.stdout.write("""\033[?25l""")
						sys.stdout.flush()

def      lowerCAmelCase_					(  )							->	Optional[Any]:







			"""simple docstring"""
			if os.name == "nt":
						a__       :						List[Any]							=  CursorInfo()
						a__       :						Optional[int]							=  ctypes.windll.kernelaa.GetStdHandle(-11)
						ctypes.windll.kernelaa.GetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
						a__       :						Dict							=  True
						ctypes.windll.kernelaa.SetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
			elif os.name == "posix":
						sys.stdout.write("""\033[?25h""")
						sys.stdout.flush()





@contextmanager
def      lowerCAmelCase_					(  )							->	Any:







			"""simple docstring"""
			try:
						hide_cursor()
						yield
			finally:
						show_cursor()




