





'''simple docstring'''






import math
from collections import OrderedDict

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

from .utils import logging


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




class 				UpperCAmelCase  (    nn.Module     ):




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




class 				UpperCAmelCase  (    nn.Module     ):




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




class 				UpperCAmelCase  (    nn.Module     ):




     def __init__(    self    :				Tuple    ,    __snake_case    :				List[str] = False						)       ->   List[Any]:
           super().__init__()
           if use_gelu_python:
                 _lowerCAmelCase							  =							self._gelu_python
           else:
                 _lowerCAmelCase							  =							nn.functional.gelu




     def        lowercase__					(    self    :				int    ,    __snake_case    :				Optional[Any]						)       ->   Tensor:
           return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0						)						))




     def        lowercase__					(    self    :				Any    ,    __snake_case    :				str						)       ->   Tensor:
           return self.act(__snake_case						)




class 				UpperCAmelCase  (    nn.Module     ):




     def        lowercase__					(    self    :				Optional[Any]    ,    __snake_case    :				List[Any]						)       ->   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 				UpperCAmelCase  (    nn.Module     ):




     def        lowercase__					(    self    :				List[Any]    ,    __snake_case    :				Dict						)       ->   Tensor:
           return input * torch.sigmoid(1.7_02 * input						)




class 				UpperCAmelCase  (    nn.Module     ):




     def __init__(    self    :				Any    ,    __snake_case    :				Dict    ,    __snake_case    :				Tuple						)       ->   Union[str, Any]:
           if min > max:
                 raise ValueError(f"min should be < max (got min: {min}, max: {max})"						)

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




     def        lowercase__					(    self    :				Any    ,    __snake_case    :				Tuple						)       ->   Tensor:
           return torch.clip(gelu(__snake_case						)    ,    self.min    ,    self.max						)




class 				UpperCAmelCase  (    nn.Module     ):




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




     def        lowercase__					(    self    :				List[Any]    ,    __snake_case    :				int						)       ->   Tensor:
           return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.04_47_15 * torch.pow(__snake_case    ,    3						))						))




class 				UpperCAmelCase  (    nn.Module     ):




     def        lowercase__					(    self    :				Tuple    ,    __snake_case    :				Optional[int]						)       ->   Tensor:
           return nn.functional.silu(__snake_case						)




class 				UpperCAmelCase  (    nn.Module     ):




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




     def        lowercase__					(    self    :				Union[str, Any]    ,    __snake_case    :				Tuple						)       ->   Tensor:
           return input * torch.tanh(nn.functional.softplus(__snake_case						)						)




     def        lowercase__					(    self    :				Dict    ,    __snake_case    :				List[str]						)       ->   Tensor:
           return self.act(__snake_case						)




class 				UpperCAmelCase  (    nn.Module     ):




     def        lowercase__					(    self    :				Union[str, Any]    ,    __snake_case    :				Optional[int]						)       ->   Tensor:
           return input




class 				UpperCAmelCase  (    nn.Module     ):




     def        lowercase__					(    self    :				List[Any]    ,    __snake_case    :				str    ,    __snake_case    :				List[str]=0.70_71_07    ,    __snake_case    :				Any=0.28_20_95						)       ->   Optional[int]:
           _lowerCAmelCase							  =							(input - mu).div(sigma * math.sqrt(2.0						)						)
           return 0.5 * (1.0 + torch.erf(__snake_case						))




class 				UpperCAmelCase  (    nn.Module     ):




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




class 				UpperCAmelCase  (    snake_case_     ):




     def __getitem__(    self    :				Dict    ,    __snake_case    :				int						)       ->   Any:
           _lowerCAmelCase							  =							super().__getitem__(__snake_case						)
           _lowerCAmelCase  ,							_lowerCAmelCase							  =							content if isinstance(__snake_case    ,    __snake_case						) else (content, {})
           return cls(**__snake_case						)




A__       :     Dict          ={
    '''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__       :     str          =ClassInstantier(ACTaCLS)
def      UpperCamelCase__   (	lowerCAmelCase						):





      """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__       :     Optional[int]          =get_activation('''gelu_python''')
A__       :     Optional[int]          =get_activation('''gelu_new''')
A__       :     Dict          =get_activation('''gelu''')
A__       :     List[str]          =get_activation('''gelu_fast''')
A__       :     Optional[int]          =get_activation('''quick_gelu''')
A__       :     int          =get_activation('''silu''')
A__       :     Tuple          =get_activation('''mish''')





A__       :     int          =get_activation('''linear''')













'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


A__       :     Tuple          ={
    '''configuration_oneformer''': ['''ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''OneFormerConfig'''],
    '''processing_oneformer''': ['''OneFormerProcessor'''],
}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__       :     List[str]          =['''OneFormerImageProcessor''']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__       :     Dict          =[
          '''ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''OneFormerForUniversalSegmentation''',
          '''OneFormerModel''',
          '''OneFormerPreTrainedModel''',
      ]

if TYPE_CHECKING:
      from .configuration_oneformer import ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, OneFormerConfig
      from .processing_oneformer import OneFormerProcessor

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .image_processing_oneformer import OneFormerImageProcessor
      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_oneformer import (
                ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                OneFormerForUniversalSegmentation,
                OneFormerModel,
                OneFormerPreTrainedModel,
            )


else:
      import sys

      A__       :     Optional[Any]          =_LazyModule(__name__, globals()['''__file__'''], _import_structure)






