
"""simple docstring"""


import math
from collections import OrderedDict

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

from .utils import logging


__A 		= logging.get_logger(__name__)







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def __init__(							self						)				->  Union[str, Any]:
				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       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return nn.functional.gelu(__UpperCAmelCase  ,  approximate="""tanh"""						)







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi						) * (input + 0.0_4_4_7_1_5 * torch.pow(__UpperCAmelCase  ,  3.0						))						))







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def __init__(							self  ,  __UpperCAmelCase = False						)				->  Tuple:
				super().__init__()
				if use_gelu_python:
					_lowerCAmelCase			=self._gelu_python
				else:
					_lowerCAmelCase			=nn.functional.gelu



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0						)						))



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return self.act(__UpperCAmelCase						)







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return 0.5 * input * (1.0 + torch.tanh(input * 0.7_9_7_8_8_4_5_6_0_8 * (1.0 + 0.0_4_4_7_1_5 * input * input)						))







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return input * torch.sigmoid(1.7_0_2 * input						)







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def __init__(							self  ,  __UpperCAmelCase  ,  __UpperCAmelCase						)				->  Tuple:
				if min > max:
					raise ValueError(f'''min should be < max (got min: {min}, max: {max})'''						)

				super().__init__()
				_lowerCAmelCase			=min
				_lowerCAmelCase			=max



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return torch.clip(gelu(__UpperCAmelCase						)  ,  self.min  ,  self.max						)







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def __init__(							self						)				->  Optional[Any]:
				super().__init__()
				_lowerCAmelCase			=math.sqrt(2 / math.pi						)



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.0_4_4_7_1_5 * torch.pow(__UpperCAmelCase  ,  3						))						))







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return nn.functional.silu(__UpperCAmelCase						)







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def __init__(							self						)				->  List[str]:
				super().__init__()
				if version.parse(torch.__version__						) < version.parse("""1.9.0"""						):
					_lowerCAmelCase			=self._mish_python
				else:
					_lowerCAmelCase			=nn.functional.mish



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return input * torch.tanh(nn.functional.softplus(__UpperCAmelCase						)						)



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return self.act(__UpperCAmelCase						)







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tensor:
				return input







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase  ,  __UpperCAmelCase=0.7_0_7_1_0_7  ,  __UpperCAmelCase=0.2_8_2_0_9_5						)				->  Tuple:
				_lowerCAmelCase			=(input - mu).div(sigma * math.sqrt(2.0						)						)
				return 0.5 * (1.0 + torch.erf(__UpperCAmelCase						))







class 	lowerCamelCase__      (      nn.Module       ):





			'''simple docstring'''



			def       _lowerCAmelCase	(							self  ,  __UpperCAmelCase						)				->  Tuple:
				_lowerCAmelCase			=nn.functional.relu(__UpperCAmelCase						)
				_lowerCAmelCase			=torch.square(__UpperCAmelCase						)
				return squared







class 	lowerCamelCase__      (      __magic_name__       ):





			'''simple docstring'''



			def __getitem__(							self  ,  __UpperCAmelCase						)				->  List[str]:
				_lowerCAmelCase			=super().__getitem__(__UpperCAmelCase						)
				_lowerCAmelCase		,							_lowerCAmelCase			=content if isinstance(__UpperCAmelCase  ,  __UpperCAmelCase						) else (content, {})
				return cls(**__UpperCAmelCase						)







__A 		= {
    '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,
}
__A 		= ClassInstantier(ACTaCLS)



def 					_lowerCamelCase(__UpperCamelCase )       ->				List[Any]:
	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
__A 		= get_activation('gelu_python')
__A 		= get_activation('gelu_new')
__A 		= get_activation('gelu')
__A 		= get_activation('gelu_fast')
__A 		= get_activation('quick_gelu')
__A 		= get_activation('silu')
__A 		= get_activation('mish')

__A 		= 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,
)


__A 		= {
    'configuration_convnextv2': [
        'CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ConvNextV2Config',
    ]
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			__A 		= [
			    '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

			__A 		= _LazyModule(__name__, globals()['__file__'], _import_structure)



