


'''simple docstring'''





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


__lowerCamelCase												=						logging.get_logger(__name__)

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




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"switch_transformers"
 UpperCAmelCase				=					["past_key_values"]
 UpperCAmelCase				=					{"hidden_size": "d_model", "num_attention_heads": "num_heads", "num_hidden_layers": "num_layers"}


 def __init__(      self							:	Any			,       __lowerCamelCase							:	Tuple=3_2_1_2_8			,       __lowerCamelCase							:	List[str]=7_6_8			,       __lowerCamelCase							:	Dict=6_4			,       __lowerCamelCase							:	Any=2_0_4_8			,       __lowerCamelCase							:	List[Any]=6_4			,       __lowerCamelCase							:	int=1_2			,       __lowerCamelCase							:	List[str]=3			,       __lowerCamelCase							:	List[Any]=1_2			,       __lowerCamelCase							:	str=3			,       __lowerCamelCase							:	str=1_2			,       __lowerCamelCase							:	List[Any]=8			,       __lowerCamelCase							:	int=False			,       __lowerCamelCase							:	Tuple=0.01			,       __lowerCamelCase							:	List[str]="float32"			,       __lowerCamelCase							:	Tuple=False			,       __lowerCamelCase							:	Any=3_2			,       __lowerCamelCase							:	Optional[int]=1_2_8			,       __lowerCamelCase							:	List[Any]=0.1			,       __lowerCamelCase							:	Dict=1e-6			,       __lowerCamelCase							:	Tuple=0.0_01			,       __lowerCamelCase							:	List[str]=0.0_01			,       __lowerCamelCase							:	Union[str, Any]=1.0			,       __lowerCamelCase							:	List[str]="relu"			,       __lowerCamelCase							:	Union[str, Any]=True			,       __lowerCamelCase							:	Union[str, Any]=False			,       __lowerCamelCase							:	List[str]=True			,       __lowerCamelCase							:	List[str]=0			,       __lowerCamelCase							:	Optional[Any]=1			,       **__lowerCamelCase							:	Optional[Any]			,       ):
    UpperCAmelCase__	:List[str]      =      vocab_size
    UpperCAmelCase__	:List[str]      =      d_model
    UpperCAmelCase__	:Any      =      d_kv
    UpperCAmelCase__	:Dict      =      d_ff

    UpperCAmelCase__	:int      =      num_sparse_encoder_layers

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

    UpperCAmelCase__	:Optional[Any]      =      num_heads
    UpperCAmelCase__	:Dict      =      num_experts
    UpperCAmelCase__	:Union[str, Any]      =      expert_capacity
    UpperCAmelCase__	:Any      =      router_bias
    UpperCAmelCase__	: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}''' )
    UpperCAmelCase__	:Tuple      =      router_dtype

    UpperCAmelCase__	:Any      =      router_ignore_padding_tokens
    UpperCAmelCase__	:Dict      =      relative_attention_num_buckets
    UpperCAmelCase__	:Optional[Any]      =      relative_attention_max_distance

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

    UpperCAmelCase__	:str      =      router_z_loss_coef
    UpperCAmelCase__	:List[str]      =      router_aux_loss_coef

    UpperCAmelCase__	:Union[str, Any]      =      self.feed_forward_proj.split('''-''' )
    UpperCAmelCase__	:int      =      act_info[-1]
    UpperCAmelCase__	:str      =      act_info[0] == '''gated'''

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

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







'''simple docstring'''





import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__lowerCamelCase												=						logging.get_logger(__name__)

__lowerCamelCase												=						{
    '''nvidia/segformer-b0-finetuned-ade-512-512''': (
        '''https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'''
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"segformer"


 def __init__(      self							:	Dict			,       __lowerCamelCase							:	Dict=3			,       __lowerCamelCase							:	List[str]=4			,       __lowerCamelCase							:	List[Any]=[2, 2, 2, 2]			,       __lowerCamelCase							:	List[str]=[8, 4, 2, 1]			,       __lowerCamelCase							:	Optional[Any]=[3_2, 6_4, 1_6_0, 2_5_6]			,       __lowerCamelCase							:	Tuple=[7, 3, 3, 3]			,       __lowerCamelCase							:	Tuple=[4, 2, 2, 2]			,       __lowerCamelCase							:	Any=[1, 2, 5, 8]			,       __lowerCamelCase							:	Optional[Any]=[4, 4, 4, 4]			,       __lowerCamelCase							:	Union[str, Any]="gelu"			,       __lowerCamelCase							:	Dict=0.0			,       __lowerCamelCase							:	Union[str, Any]=0.0			,       __lowerCamelCase							:	Tuple=0.1			,       __lowerCamelCase							:	Optional[Any]=0.02			,       __lowerCamelCase							:	Optional[int]=0.1			,       __lowerCamelCase							:	str=1e-6			,       __lowerCamelCase							:	List[Any]=2_5_6			,       __lowerCamelCase							:	int=2_5_5			,       **__lowerCamelCase							:	str			,       ):
    super().__init__(**__lowerCamelCase )

    if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
       warnings.warn(
           '''Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be'''
           ''' removed, as the behaviour will default to that of reshape_last_stage = True.'''			,       __lowerCamelCase			,       )

    UpperCAmelCase__	:Dict      =      num_channels
    UpperCAmelCase__	:List[Any]      =      num_encoder_blocks
    UpperCAmelCase__	:List[str]      =      depths
    UpperCAmelCase__	:str      =      sr_ratios
    UpperCAmelCase__	:Optional[Any]      =      hidden_sizes
    UpperCAmelCase__	:List[str]      =      patch_sizes
    UpperCAmelCase__	:List[str]      =      strides
    UpperCAmelCase__	:List[str]      =      mlp_ratios
    UpperCAmelCase__	:Dict      =      num_attention_heads
    UpperCAmelCase__	:Tuple      =      hidden_act
    UpperCAmelCase__	:List[str]      =      hidden_dropout_prob
    UpperCAmelCase__	:List[Any]      =      attention_probs_dropout_prob
    UpperCAmelCase__	:int      =      classifier_dropout_prob
    UpperCAmelCase__	:str      =      initializer_range
    UpperCAmelCase__	:List[str]      =      drop_path_rate
    UpperCAmelCase__	:Dict      =      layer_norm_eps
    UpperCAmelCase__	:List[str]      =      decoder_hidden_size
    UpperCAmelCase__	:Optional[int]      =      kwargs.get('''reshape_last_stage'''			,       __lowerCamelCase )
    UpperCAmelCase__	:str      =      semantic_loss_ignore_index




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					version.parse("1.11"						)


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[Any] ):
    return OrderedDict(
        [
            ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
        ] )


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[int] ):
    return 1e-4





 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	List[str] ):
    return 1_2



