
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 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def __init__(	self  :      int	)	->					int:
					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 						_lowercase  (	self  :      Optional[int]	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return nn.functional.gelu(SCREAMING_SNAKE_CASE_	,							approximate='''tanh'''	)

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def 						_lowercase  (	self  :      Optional[Any]	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi	) * (input + 0.04_47_15 * torch.pow(SCREAMING_SNAKE_CASE_	,							3.0	))	))

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def __init__(	self  :      Dict	,							SCREAMING_SNAKE_CASE_  :      bool = False	)	->					Optional[Any]:
					super().__init__()
					if use_gelu_python:
									lowercase_					  = self._gelu_python
					else:
									lowercase_					  = nn.functional.gelu
	def 						_lowercase  (	self  :      Optional[int]	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0	)	))




	def 						_lowercase  (	self  :      List[Any]	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return self.act(SCREAMING_SNAKE_CASE_	)

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def 						_lowercase  (	self  :      Optional[Any]	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return 0.5 * input * (1.0 + torch.tanh(input * 0.79_78_84_56_08 * (1.0 + 0.04_47_15 * input * input)	))

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def 						_lowercase  (	self  :      Union[str, Any]	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return input * torch.sigmoid(1.7_02 * input	)

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def __init__(	self  :      Optional[int]	,							SCREAMING_SNAKE_CASE_  :      float	,							SCREAMING_SNAKE_CASE_  :      float	)	->					Any:
					if min > max:
									raise ValueError(f'''min should be < max (got min: {min}, max: {max})'''	)

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




	def 						_lowercase  (	self  :      Any	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return torch.clip(gelu(SCREAMING_SNAKE_CASE_	)	,							self.min	,							self.max	)

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def __init__(	self  :      Tuple	)	->					Tuple:
					super().__init__()
					lowercase_					  = math.sqrt(2 / math.pi	)




	def 						_lowercase  (	self  :      Any	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.04_47_15 * torch.pow(SCREAMING_SNAKE_CASE_	,							3	))	))

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def 						_lowercase  (	self  :      Tuple	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return nn.functional.silu(SCREAMING_SNAKE_CASE_	)

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def __init__(	self  :      Union[str, Any]	)	->					Dict:
					super().__init__()
					if version.parse(torch.__version__	) < version.parse('''1.9.0'''	):
									lowercase_					  = self._mish_python
					else:
									lowercase_					  = nn.functional.mish
	def 						_lowercase  (	self  :      Any	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return input * torch.tanh(nn.functional.softplus(SCREAMING_SNAKE_CASE_	)	)




	def 						_lowercase  (	self  :      Any	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return self.act(SCREAMING_SNAKE_CASE_	)

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def 						_lowercase  (	self  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      Tensor	)	->					Tensor:
					return input

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def 						_lowercase  (	self  :      Dict	,							SCREAMING_SNAKE_CASE_  :      int	,							SCREAMING_SNAKE_CASE_  :      int=0.70_71_07	,							SCREAMING_SNAKE_CASE_  :      Dict=0.28_20_95	)	->					Any:
					lowercase_					  = (input - mu).div(sigma * math.sqrt(2.0	)	)
					return 0.5 * (1.0 + torch.erf(SCREAMING_SNAKE_CASE_	))

class 			lowercase__(    nn.Module							):



	"""simple docstring"""




	def 						_lowercase  (	self  :      List[Any]	,							SCREAMING_SNAKE_CASE_  :      int	)	->					Optional[Any]:
					lowercase_					  = nn.functional.relu(SCREAMING_SNAKE_CASE_	)
					lowercase_					  = torch.square(SCREAMING_SNAKE_CASE_	)
					return squared

class 			lowercase__(    UpperCAmelCase							):



	"""simple docstring"""




	def __getitem__(	self  :      Tuple	,							SCREAMING_SNAKE_CASE_  :      List[Any]	)	->					int:
					lowercase_					  = super().__getitem__(SCREAMING_SNAKE_CASE_	)
					lowercase_  ,     lowercase_					  = content if isinstance(SCREAMING_SNAKE_CASE_	,							SCREAMING_SNAKE_CASE_	) else (content, {})
					return cls(**SCREAMING_SNAKE_CASE_	)

__a        = {
    'gelu': GELUActivation,
    'gelu_10': (ClippedGELUActivation, {'min': -1_0, 'max': 1_0}),
    '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     a						(							snake_case__: List[Any] ):


				'''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
__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')






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


__a        = {
    'configuration_speech_to_text_2': ['SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'Speech2Text2Config'],
    'processing_speech_to_text_2': ['Speech2Text2Processor'],
    'tokenization_speech_to_text_2': ['Speech2Text2Tokenizer'],
}


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a        = [
						    'SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'Speech2Text2ForCausalLM',
						    'Speech2Text2PreTrainedModel',
						]


if TYPE_CHECKING:
						from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
						from .processing_speech_to_text_a import SpeechaTextaProcessor
						from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_speech_to_text_a import (
												    SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
												    SpeechaTextaForCausalLM,
												    SpeechaTextaPreTrainedModel,
												)

else:
						import sys

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




