

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


a_     =			logging.get_logger(__name__)

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






class _UpperCamelCase							(							_UpperCAmelCase      ):
			'''simple docstring'''







			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]					,					a							:       Dict=3_2128					,					a							:       Any=768					,					a							:       Optional[Any]=64					,					a							:       Union[str, Any]=2048					,					a							:       Any=64					,					a							:       List[str]=12					,					a							:       Any=3					,					a							:       Optional[int]=12					,					a							:       List[str]=3					,					a							:       Optional[Any]=12					,					a							:       List[Any]=8					,					a							:       Tuple=False					,					a							:       Any=0.01					,					a							:       Tuple="float32"					,					a							:       str=False					,					a							:       List[Any]=32					,					a							:       Tuple=128					,					a							:       Any=0.1					,					a							:       Union[str, Any]=1e-6					,					a							:       Any=0.001					,					a							:       Dict=0.001					,					a							:       List[str]=1.0					,					a							:       List[Any]="relu"					,					a							:       str=True					,					a							:       Tuple=False					,					a							:       int=True					,					a							:       Optional[int]=0					,					a							:       Optional[int]=1					,					**a							:       Any					,					)							->				int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					str    =				vocab_size
				SCREAMING_SNAKE_CASE      :					Dict    =				d_model
				SCREAMING_SNAKE_CASE      :					List[str]    =				d_kv
				SCREAMING_SNAKE_CASE      :					Dict    =				d_ff

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				num_sparse_encoder_layers

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

				SCREAMING_SNAKE_CASE      :					str    =				num_heads
				SCREAMING_SNAKE_CASE      :					Tuple    =				num_experts
				SCREAMING_SNAKE_CASE      :					str    =				expert_capacity
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				router_bias
				SCREAMING_SNAKE_CASE      :					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}"		)
				SCREAMING_SNAKE_CASE      :					int    =				router_dtype

				SCREAMING_SNAKE_CASE      :					int    =				router_ignore_padding_tokens
				SCREAMING_SNAKE_CASE      :					Tuple    =				relative_attention_num_buckets
				SCREAMING_SNAKE_CASE      :					Dict    =				relative_attention_max_distance

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

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

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

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

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



'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__		:					List[Any]												=  {
    """configuration_megatron_bert""": ["""MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MegatronBertConfig"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__		:					int												=  [
          """MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """MegatronBertForCausalLM""",
          """MegatronBertForMaskedLM""",
          """MegatronBertForMultipleChoice""",
          """MegatronBertForNextSentencePrediction""",
          """MegatronBertForPreTraining""",
          """MegatronBertForQuestionAnswering""",
          """MegatronBertForSequenceClassification""",
          """MegatronBertForTokenClassification""",
          """MegatronBertModel""",
          """MegatronBertPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_megatron_bert import MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, MegatronBertConfig

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_megatron_bert import (
                MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                MegatronBertForCausalLM,
                MegatronBertForMaskedLM,
                MegatronBertForMultipleChoice,
                MegatronBertForNextSentencePrediction,
                MegatronBertForPreTraining,
                MegatronBertForQuestionAnswering,
                MegatronBertForSequenceClassification,
                MegatronBertForTokenClassification,
                MegatronBertModel,
                MegatronBertPreTrainedModel,
            )

else:
      import sys

      A__		:					List[Any]												=  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






