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


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

__lowerCAmelCase    :	List[str]						=						{
    "google/switch-base-8": "https://huggingface.co/google/switch-base-8/blob/main/config.json",
}


class   __lowerCAmelCase		(		_UpperCAmelCase					):



      """simple docstring"""







      A__		:	List[str]         =			'''switch_transformers'''
      A__		:	Optional[int]         =			['''past_key_values''']
      A__		:	int         =			{'''hidden_size''': '''d_model''', '''num_attention_heads''': '''num_heads''', '''num_hidden_layers''': '''num_layers'''}




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

          __lowercase						:	int					=				num_sparse_encoder_layers

          __lowercase						:	Union[str, Any]					=				num_layers
          __lowercase						:	Tuple					=				(
              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						:	Tuple					=				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						:	List[Any]					=				self.num_decoder_layers // self.num_sparse_decoder_layers
          else:
              __lowercase						:	List[Any]					=				self.num_decoder_layers  # HACK: this will create 0 sparse layers

          __lowercase						:	int					=				num_heads
          __lowercase						:	int					=				num_experts
          __lowercase						:	Union[str, Any]					=				expert_capacity
          __lowercase						:	List[Any]					=				router_bias
          __lowercase						:	List[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						:	int					=				router_dtype

          __lowercase						:	Optional[int]					=				router_ignore_padding_tokens
          __lowercase						:	int					=				relative_attention_num_buckets
          __lowercase						:	Union[str, Any]					=				relative_attention_max_distance

          __lowercase						:	int					=				dropout_rate
          __lowercase						:	List[Any]					=				layer_norm_epsilon
          __lowercase						:	Union[str, Any]					=				initializer_factor
          __lowercase						:	List[Any]					=				feed_forward_proj
          __lowercase						:	Dict					=				use_cache
          __lowercase						:	int					=				add_router_probs

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

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

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





from typing import Dict

from .base import GenericTensor, Pipeline


class  A						(							_UpperCAmelCase ):







    """simple docstring"""





    def 						snake_case__     (      self :       int,lowercase_ :       Dict=None,lowercase_ :       Tuple=None,lowercase_ :       List[Any]=None,**lowercase_ :       Any		)->    Optional[Any]:





        '''simple docstring'''







        if tokenize_kwargs is None:
            A__          =   {}

        if truncation is not None:
            if "truncation" in tokenize_kwargs:
                raise ValueError(
                    'truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)'		)
            A__          =   truncation

        A__          =   tokenize_kwargs

        A__          =   {}
        if return_tensors is not None:
            A__          =   return_tensors

        return preprocess_params, {}, postprocess_params


    def 						snake_case__     (      self :       Dict,lowercase_ :       List[Any],**lowercase_ :       Tuple		)->    Dict[str, GenericTensor]:





        '''simple docstring'''







        A__          =   self.framework
        A__          =   self.tokenizer(lowercase_,return_tensors=lowercase_,**lowercase_		)
        return model_inputs


    def 						snake_case__     (      self :       Tuple,lowercase_ :       int		)->    Optional[Any]:





        '''simple docstring'''







        A__          =   self.model(**lowercase_		)
        return model_outputs


    def 						snake_case__     (      self :       Tuple,lowercase_ :       Tuple,lowercase_ :       List[str]=False		)->    Any:





        '''simple docstring'''







        if return_tensors:
            return model_outputs[0]
        if self.framework == "pt":
            return model_outputs[0].tolist()
        elif self.framework == "tf":
            return model_outputs[0].numpy().tolist()


    def __call__(      self :       List[Any],*lowercase_ :       int,**lowercase_ :       Optional[Any]		)->    int:





        '''simple docstring'''







        return super().__call__(*lowercase_,**lowercase_		)

