






"""simple docstring"""



import math
from collections import OrderedDict

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

from .utils import logging


_lowerCAmelCase  :  str   =			logging.get_logger(__name__)




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


        '''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			:  Tuple       , snake_case__			:  Tensor       ):


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




class  lowerCAmelCase__ (						nn.Module      ):
   def 			__a       (		self			:  List[str]       , 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			:  Tuple       , snake_case__			:  bool = False       ):


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


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




   def 			__a       (		self			:  List[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			:  int       , snake_case__			:  Tensor       ):


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




class  lowerCAmelCase__ (						nn.Module      ):
   def __init__(		self			:  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__	:						Union[str, Any]       =       min
        UpperCAmelCase__	:						List[str]       =       max




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


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




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


        '''simple docstring'''
        super().__init__()
        UpperCAmelCase__	:						str       =       math.sqrt(2 / math.pi       )




   def 			__a       (		self			:  Dict       , 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			:  List[Any]       , snake_case__			:  Tensor       ):


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




class  lowerCAmelCase__ (						nn.Module      ):
   def __init__(		self			:  Union[str, Any]       ):


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


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




   def 			__a       (		self			:  Union[str, Any]       , 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			:  Any       , snake_case__			:  List[str]       , snake_case__			:  List[Any]=0.70_7107       , snake_case__			:  Union[str, Any]=0.28_2095       ):


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




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


        '''simple docstring'''
        UpperCAmelCase__	:						Any       =       nn.functional.relu(snake_case__       )
        UpperCAmelCase__	:						Union[str, Any]       =       torch.square(snake_case__       )
        return squared




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


        '''simple docstring'''
        UpperCAmelCase__	:						str       =       super().__getitem__(snake_case__       )
        UpperCAmelCase__       ,							UpperCAmelCase__	:						List[Any]       =       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  :  Tuple   =			ClassInstantier(ACTaCLS)


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


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



_lowerCAmelCase  :  Optional[int]   =			get_activation("""linear""")










"""simple docstring"""



# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


_lowerCAmelCase  :  Optional[Any]   =			{
    """configuration_convnextv2""": [
        """CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """ConvNextV2Config""",
    ]
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase  :  str   =			[
     """CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """ConvNextV2ForImageClassification""",
     """ConvNextV2Model""",
     """ConvNextV2PreTrainedModel""",
     """ConvNextV2Backbone""",
 ]


if TYPE_CHECKING:
 from .configuration_convnextva import (
     CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
     ConvNextVaConfig,
 )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_convnextva import (
      CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST,
      ConvNextVaBackbone,
      ConvNextVaForImageClassification,
      ConvNextVaModel,
      ConvNextVaPreTrainedModel,
  )

else:
 import sys

 _lowerCAmelCase  :  List[str]   =			_LazyModule(__name__, globals()["""__file__"""], _import_structure)


