
import math

import tensorflow as tf
from packaging import version



def 						lowercase_      (       A__		)							->							int:
    """simple docstring"""

    snake_case								= tf.convert_to_tensor(A__		)
    snake_case								= 0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0		)			,		x.dtype		)		))

    return x * cdf



def 						lowercase_      (       A__		)							->							str:
    """simple docstring"""

    snake_case								= tf.convert_to_tensor(A__		)
    snake_case								= tf.cast(math.pi			,		x.dtype		)
    snake_case								= tf.cast(0.044715			,		x.dtype		)
    snake_case								= 0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi		) * (x + coeff * tf.pow(A__			,		3		))		))

    return x * cdf



def 						lowercase_      (       A__		)							->							Tuple:
    """simple docstring"""

    snake_case								= tf.convert_to_tensor(A__		)

    return x * tf.tanh(tf.math.softplus(A__		)		)



def 						lowercase_      (       A__		)							->							str:
    """simple docstring"""

    snake_case								= tf.convert_to_tensor(A__		)
    snake_case								= tf.cast(0.044715			,		x.dtype		)
    snake_case								= tf.cast(0.7978845608			,		x.dtype		)

    return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)		))



def 						lowercase_      (       A__		)							->							Union[str, Any]:
    """simple docstring"""

    snake_case								= tf.convert_to_tensor(A__		)
    snake_case								= tf.cast(1.702			,		x.dtype		)
    return x * tf.math.sigmoid(coeff * x		)



def 						lowercase_      (       A__		)							->							Dict:
    """simple docstring"""

    return tf.clip_by_value(_gelu(A__		)			,		-10			,		10		)



def 						lowercase_      (       A__			,		A__=-1		)							->							Dict:
    """simple docstring"""

    snake_case					,							snake_case								= tf.split(A__			,		2			,		axis=A__		)
    return a * tf.math.sigmoid(A__		)


if version.parse(tf.version.VERSION) >= version.parse("2.4"):



   def 						lowercase_      (       A__		)							->							List[str]:
       """simple docstring"""

       return tf.keras.activations.gelu(A__			,		approximate=A__		)

   _A   =			tf.keras.activations.gelu





   _A   =			approximate_gelu_wrap
else:
   _A   =			_gelu
   _A   =			_gelu_new


_A   =			{
    "gelu": gelu,
    "gelu_10": gelu_aa,
    "gelu_fast": gelu_fast,
    "gelu_new": gelu_new,
    "glu": glu,
    "mish": mish,
    "quick_gelu": quick_gelu,
    "relu": tf.keras.activations.relu,
    "sigmoid": tf.keras.activations.sigmoid,
    "silu": tf.keras.activations.swish,
    "swish": tf.keras.activations.swish,
    "tanh": tf.keras.activations.tanh,
}





def 						lowercase_      (       A__		)							->							List[str]:
    """simple docstring"""

    if activation_string in ACTaFN:
        return ACTaFN[activation_string]
    else:
        raise KeyError(F'function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()		)}'		)



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


_A   =			logging.get_logger(__name__)

_A   =			{
    "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 					lowerCamelCase		(  A_  ):
     UpperCAmelCase__    :							List[Any]									=		"segformer"





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

         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."    ,   _A    ,   )

         snake_case								= num_channels
         snake_case								= num_encoder_blocks
         snake_case								= depths
         snake_case								= sr_ratios
         snake_case								= hidden_sizes
         snake_case								= patch_sizes
         snake_case								= strides
         snake_case								= mlp_ratios
         snake_case								= num_attention_heads
         snake_case								= hidden_act
         snake_case								= hidden_dropout_prob
         snake_case								= attention_probs_dropout_prob
         snake_case								= classifier_dropout_prob
         snake_case								= initializer_range
         snake_case								= drop_path_rate
         snake_case								= layer_norm_eps
         snake_case								= decoder_hidden_size
         snake_case								= kwargs.get("reshape_last_stage"    ,   _A       )
         snake_case								= semantic_loss_ignore_index







class 					lowerCamelCase		(  A_  ):
     UpperCAmelCase__    :							Optional[Any]									=		version.parse("1.11"  )





     @property
     def 		UpperCAmelCase(self				:   Tuple       )						->						Mapping[str, Mapping[int, str]]:
         return OrderedDict(
             [
                 ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
             ]       )





     @property
     def 		UpperCAmelCase(self				:   Tuple       )						->						float:
         return 1E-4





     @property
     def 		UpperCAmelCase(self				:   List[str]       )						->						int:
         return 1_2

