






"""simple docstring"""



import math
from collections import OrderedDict

import torch
from packaging import version
from torch import Tensor, nn

from .utils import logging


_lowerCAmelCase     :     List[str]            =	logging.get_logger(__name__)




class        lowerCAmelCase__       (  nn.Module					):
   def __init__(						self	:     Tuple				):


        '''simple docstring'''
        super().__init__()
        if version.parse(torch.__version__				) < version.parse("1.12.0"				):
             raise ImportError(
                 f'You are using torch=={torch.__version__}, but torch>=1.12.0 is required to use '
                 "PytorchGELUTanh. Please upgrade torch."				)




   def 	__a				(						self	:     Optional[int]				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return nn.functional.gelu(snake_case__				,       approximate="tanh"				)




class        lowerCAmelCase__       (  nn.Module					):
   def 	__a				(						self	:     Tuple				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi				) * (input + 0.04_4715 * torch.pow(snake_case__				,       3.0				))				))




class        lowerCAmelCase__       (  nn.Module					):
   def __init__(						self	:     List[str]				,       snake_case__	:     bool = False				):


        '''simple docstring'''
        super().__init__()
        if use_gelu_python:
             UpperCAmelCase__		:  int				=				self._gelu_python
        else:
             UpperCAmelCase__		:  Optional[int]				=				nn.functional.gelu
   def 	__a				(						self	:     int				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0				)				))




   def 	__a				(						self	:     Any				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return self.act(snake_case__				)




class        lowerCAmelCase__       (  nn.Module					):
   def 	__a				(						self	:     int				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return 0.5 * input * (1.0 + torch.tanh(input * 0.79_7884_5608 * (1.0 + 0.04_4715 * input * input)				))




class        lowerCAmelCase__       (  nn.Module					):
   def 	__a				(						self	:     Optional[Any]				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return input * torch.sigmoid(1.702 * input				)




class        lowerCAmelCase__       (  nn.Module					):
   def __init__(						self	:     Optional[Any]				,       snake_case__	:     float				,       snake_case__	:     float				):


        '''simple docstring'''
        if min > max:
             raise ValueError(f'min should be < max (got min: {min}, max: {max})'				)

        super().__init__()
        UpperCAmelCase__		:  Any				=				min
        UpperCAmelCase__		:  str				=				max




   def 	__a				(						self	:     List[Any]				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return torch.clip(gelu(snake_case__				)				,       self.min				,       self.max				)




class        lowerCAmelCase__       (  nn.Module					):
   def __init__(						self	:     List[str]				):


        '''simple docstring'''
        super().__init__()
        UpperCAmelCase__		:  List[Any]				=				math.sqrt(2 / math.pi				)




   def 	__a				(						self	:     Union[str, Any]				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.04_4715 * torch.pow(snake_case__				,       3				))				))




class        lowerCAmelCase__       (  nn.Module					):
   def 	__a				(						self	:     str				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return nn.functional.silu(snake_case__				)




class        lowerCAmelCase__       (  nn.Module					):
   def __init__(						self	:     int				):


        '''simple docstring'''
        super().__init__()
        if version.parse(torch.__version__				) < version.parse("1.9.0"				):
             UpperCAmelCase__		:  List[Any]				=				self._mish_python
        else:
             UpperCAmelCase__		:  Dict				=				nn.functional.mish
   def 	__a				(						self	:     Tuple				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return input * torch.tanh(nn.functional.softplus(snake_case__				)				)




   def 	__a				(						self	:     int				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return self.act(snake_case__				)




class        lowerCAmelCase__       (  nn.Module					):
   def 	__a				(						self	:     Any				,       snake_case__	:     Tensor				):


        '''simple docstring'''
        return input




class        lowerCAmelCase__       (  nn.Module					):
   def 	__a				(						self	:     str				,       snake_case__	:     List[str]				,       snake_case__	:     List[Any]=0.70_7107				,       snake_case__	:     Optional[Any]=0.28_2095				):


        '''simple docstring'''
        UpperCAmelCase__		:  Any				=				(input - mu).div(sigma * math.sqrt(2.0				)				)
        return 0.5 * (1.0 + torch.erf(snake_case__				))




class        lowerCAmelCase__       (  nn.Module					):
   def 	__a				(						self	:     Optional[int]				,       snake_case__	:     List[Any]				):


        '''simple docstring'''
        UpperCAmelCase__		:  int				=				nn.functional.relu(snake_case__				)
        UpperCAmelCase__		:  Any				=				torch.square(snake_case__				)
        return squared




class        lowerCAmelCase__       (  __magic_name__					):
   def __getitem__(						self	:     List[Any]				,       snake_case__	:     Optional[int]				):


        '''simple docstring'''
        UpperCAmelCase__		:  Optional[Any]				=				super().__getitem__(snake_case__				)
        UpperCAmelCase__				,							UpperCAmelCase__		:  str				=				content if isinstance(snake_case__				,       snake_case__				) else (content, {})
        return cls(**snake_case__				)




_lowerCAmelCase     :     Union[str, Any]            =	{
    """gelu""": GELUActivation,
    """gelu_10""": (ClippedGELUActivation, {"""min""": -10, """max""": 10}),
    """gelu_fast""": FastGELUActivation,
    """gelu_new""": NewGELUActivation,
    """gelu_python""": (GELUActivation, {"""use_gelu_python""": True}),
    """gelu_pytorch_tanh""": PytorchGELUTanh,
    """gelu_accurate""": AccurateGELUActivation,
    """laplace""": LaplaceActivation,
    """linear""": LinearActivation,
    """mish""": MishActivation,
    """quick_gelu""": QuickGELUActivation,
    """relu""": nn.ReLU,
    """relu2""": ReLUSquaredActivation,
    """relu6""": nn.ReLUa,
    """sigmoid""": nn.Sigmoid,
    """silu""": SiLUActivation,
    """swish""": SiLUActivation,
    """tanh""": nn.Tanh,
}
_lowerCAmelCase     :     Union[str, Any]            =	ClassInstantier(ACTaCLS)


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      List[str]							)->						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()							)}'							)


# For backwards compatibility with: from activations import gelu_python
_lowerCAmelCase     :     Union[str, Any]            =	get_activation("""gelu_python""")
_lowerCAmelCase     :     Any            =	get_activation("""gelu_new""")
_lowerCAmelCase     :     Union[str, Any]            =	get_activation("""gelu""")
_lowerCAmelCase     :     Union[str, Any]            =	get_activation("""gelu_fast""")
_lowerCAmelCase     :     Tuple            =	get_activation("""quick_gelu""")
_lowerCAmelCase     :     int            =	get_activation("""silu""")
_lowerCAmelCase     :     Any            =	get_activation("""mish""")



_lowerCAmelCase     :     List[Any]            =	get_activation("""linear""")



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase__							= {
    'configuration_deberta_v2': ['DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DebertaV2Config', 'DebertaV2OnnxConfig'],
    'tokenization_deberta_v2': ['DebertaV2Tokenizer'],
}

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__							= ['DebertaV2TokenizerFast']

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__							= [
        'TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST',
        'TFDebertaV2ForMaskedLM',
        'TFDebertaV2ForQuestionAnswering',
        'TFDebertaV2ForSequenceClassification',
        'TFDebertaV2ForTokenClassification',
        'TFDebertaV2Model',
        'TFDebertaV2PreTrainedModel',
    ]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__							= [
        'DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST',
        'DebertaV2ForMaskedLM',
        'DebertaV2ForMultipleChoice',
        'DebertaV2ForQuestionAnswering',
        'DebertaV2ForSequenceClassification',
        'DebertaV2ForTokenClassification',
        'DebertaV2Model',
        'DebertaV2PreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_deberta_va import (
        DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP,
        DebertaVaConfig,
        DebertaVaOnnxConfig,
    )
    from .tokenization_deberta_va import DebertaVaTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_deberta_va_fast import DebertaVaTokenizerFast

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_deberta_va import (
            TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
            TFDebertaVaModel,
            TFDebertaVaPreTrainedModel,
        )

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_deberta_va import (
            DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
            DebertaVaForMaskedLM,
            DebertaVaForMultipleChoice,
            DebertaVaForQuestionAnswering,
            DebertaVaForSequenceClassification,
            DebertaVaForTokenClassification,
            DebertaVaModel,
            DebertaVaPreTrainedModel,
        )

else:
    import sys

    lowerCAmelCase__							= _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
