


def      __lowerCAmelCase    (				snake_case						:     int			)							->				int:
   return 1 if input_a == 0 else 0



def      __lowerCAmelCase    (				)							->				None:
   assert not_gate(0			) == 1
   assert not_gate(1			) == 0


if __name__ == "__main__":
   print(not_gate(0))
   print(not_gate(1))






import math
from collections import OrderedDict

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

from .utils import logging


_A		:					Optional[int]          =							logging.get_logger(__name__)



class 							a       (      nn.Module ):





     def __init__(     self       :					Dict				):
        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 			SCREAMING_SNAKE_CASE__							(     self       :					int     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return nn.functional.gelu(SCREAMING_SNAKE_CASE_     ,						approximate="""tanh"""				)



class 							a       (      nn.Module ):





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Any     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi				) * (input + 0.04_4715 * torch.pow(SCREAMING_SNAKE_CASE_     ,						3.0				))				))



class 							a       (      nn.Module ):





     def __init__(     self       :					List[Any]     ,						SCREAMING_SNAKE_CASE_       :					bool = False				):
        super().__init__()
        if use_gelu_python:
           __lowerCamelCase:					Union[str, Any]	 =						self._gelu_python
        else:
           __lowerCamelCase:					Tuple	 =						nn.functional.gelu





     def 			SCREAMING_SNAKE_CASE__							(     self       :					str     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0				)				))







     def 			SCREAMING_SNAKE_CASE__							(     self       :					Union[str, Any]     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return self.act(SCREAMING_SNAKE_CASE_				)



class 							a       (      nn.Module ):





     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[str]     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return 0.5 * input * (1.0 + torch.tanh(input * 0.79_7884_5608 * (1.0 + 0.04_4715 * input * input)				))



class 							a       (      nn.Module ):





     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[Any]     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return input * torch.sigmoid(1.702 * input				)



class 							a       (      nn.Module ):





     def __init__(     self       :					List[str]     ,						SCREAMING_SNAKE_CASE_       :					float     ,						SCREAMING_SNAKE_CASE_       :					float				):
        if min > max:
           raise ValueError(F'min should be < max (got min: {min}, max: {max})'				)

        super().__init__()
        __lowerCamelCase:					Optional[int]	 =						min
        __lowerCamelCase:					str	 =						max







     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[str]     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return torch.clip(gelu(SCREAMING_SNAKE_CASE_				)     ,						self.min     ,						self.max				)



class 							a       (      nn.Module ):





     def __init__(     self       :					int				):
        super().__init__()
        __lowerCamelCase:					List[str]	 =						math.sqrt(2 / math.pi				)







     def 			SCREAMING_SNAKE_CASE__							(     self       :					Tuple     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.04_4715 * torch.pow(SCREAMING_SNAKE_CASE_     ,						3				))				))



class 							a       (      nn.Module ):





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Any     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return nn.functional.silu(SCREAMING_SNAKE_CASE_				)



class 							a       (      nn.Module ):





     def __init__(     self       :					Any				):
        super().__init__()
        if version.parse(torch.__version__				) < version.parse("""1.9.0"""				):
           __lowerCamelCase:					str	 =						self._mish_python
        else:
           __lowerCamelCase:					Any	 =						nn.functional.mish





     def 			SCREAMING_SNAKE_CASE__							(     self       :					int     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return input * torch.tanh(nn.functional.softplus(SCREAMING_SNAKE_CASE_				)				)







     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[str]     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return self.act(SCREAMING_SNAKE_CASE_				)



class 							a       (      nn.Module ):





     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[str]     ,						SCREAMING_SNAKE_CASE_       :					Tensor				):
        return input



class 							a       (      nn.Module ):





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[int]     ,						SCREAMING_SNAKE_CASE_       :					str     ,						SCREAMING_SNAKE_CASE_       :					Optional[int]=0.70_7107     ,						SCREAMING_SNAKE_CASE_       :					Tuple=0.28_2095				):
        __lowerCamelCase:					Optional[Any]	 =						(input - mu).div(sigma * math.sqrt(2.0				)				)
        return 0.5 * (1.0 + torch.erf(SCREAMING_SNAKE_CASE_				))



class 							a       (      nn.Module ):





     def 			SCREAMING_SNAKE_CASE__							(     self       :					int     ,						SCREAMING_SNAKE_CASE_       :					str				):
        __lowerCamelCase:					Any	 =						nn.functional.relu(SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					List[str]	 =						torch.square(SCREAMING_SNAKE_CASE_				)
        return squared



class 							a       (      _UpperCAmelCase ):





     def __getitem__(     self       :					str     ,						SCREAMING_SNAKE_CASE_       :					Tuple				):
        __lowerCamelCase:					Optional[Any]	 =						super().__getitem__(SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase ,  __lowerCamelCase:					Optional[Any]	 =						content if isinstance(SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_				) else (content, {})
        return cls(**SCREAMING_SNAKE_CASE_				)



_A		:					Optional[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,
}
_A		:					Optional[int]          =							ClassInstantier(ACTaCLS)



def      __lowerCAmelCase    (				snake_case						:     Any			)							->				int:
   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		:					Optional[int]          =							get_activation('''gelu_python''')
_A		:					Dict          =							get_activation('''gelu_new''')
_A		:					List[str]          =							get_activation('''gelu''')
_A		:					Tuple          =							get_activation('''gelu_fast''')
_A		:					int          =							get_activation('''quick_gelu''')
_A		:					Tuple          =							get_activation('''silu''')
_A		:					Optional[Any]          =							get_activation('''mish''')







_A		:					Dict          =							get_activation('''linear''')


