
'''simple docstring'''





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase            = logging.get_logger(__name__)

UpperCAmelCase            = {
    "google/mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/config.json"
}

class     a (					__magic_name__     ):
				_snake_case		     =			MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP
				_snake_case		     =			'''mobilebert'''




				def __init__(				self						:					Any,     SCREAMING_SNAKE_CASE_						:					int=3_05_22,     SCREAMING_SNAKE_CASE_						:					List[Any]=5_12,     SCREAMING_SNAKE_CASE_						:					str=24,     SCREAMING_SNAKE_CASE_						:					List[Any]=4,     SCREAMING_SNAKE_CASE_						:					Optional[Any]=5_12,     SCREAMING_SNAKE_CASE_						:					int="relu",     SCREAMING_SNAKE_CASE_						:					Tuple=0.0,     SCREAMING_SNAKE_CASE_						:					Dict=0.1,     SCREAMING_SNAKE_CASE_						:					Optional[Any]=5_12,     SCREAMING_SNAKE_CASE_						:					int=2,     SCREAMING_SNAKE_CASE_						:					Dict=0.02,     SCREAMING_SNAKE_CASE_						:					List[str]=1e-12,     SCREAMING_SNAKE_CASE_						:					List[Any]=0,     SCREAMING_SNAKE_CASE_						:					Any=1_28,     SCREAMING_SNAKE_CASE_						:					Tuple=True,     SCREAMING_SNAKE_CASE_						:					Dict=True,     SCREAMING_SNAKE_CASE_						:					List[str]=1_28,     SCREAMING_SNAKE_CASE_						:					Optional[Any]=False,     SCREAMING_SNAKE_CASE_						:					List[Any]=True,     SCREAMING_SNAKE_CASE_						:					Any=4,     SCREAMING_SNAKE_CASE_						:					Dict="no_norm",     SCREAMING_SNAKE_CASE_						:					Any=True,     SCREAMING_SNAKE_CASE_						:					Optional[int]=None,     **SCREAMING_SNAKE_CASE_						:					str,     ):
										super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_,     **SCREAMING_SNAKE_CASE_   )

										snake_case							:  str			=     vocab_size
										snake_case							:  Optional[Any]			=     hidden_size
										snake_case							:  Union[str, Any]			=     num_hidden_layers
										snake_case							:  str			=     num_attention_heads
										snake_case							:  Tuple			=     hidden_act
										snake_case							:  Optional[int]			=     intermediate_size
										snake_case							:  str			=     hidden_dropout_prob
										snake_case							:  Any			=     attention_probs_dropout_prob
										snake_case							:  Dict			=     max_position_embeddings
										snake_case							:  List[str]			=     type_vocab_size
										snake_case							:  int			=     initializer_range
										snake_case							:  List[Any]			=     layer_norm_eps
										snake_case							:  Any			=     embedding_size
										snake_case							:  Tuple			=     trigram_input
										snake_case							:  str			=     use_bottleneck
										snake_case							:  Union[str, Any]			=     intra_bottleneck_size
										snake_case							:  Any			=     use_bottleneck_attention
										snake_case							:  Tuple			=     key_query_shared_bottleneck
										snake_case							:  int			=     num_feedforward_networks
										snake_case							:  Union[str, Any]			=     normalization_type
										snake_case							:  Union[str, Any]			=     classifier_activation

										if self.use_bottleneck:
																snake_case							:  Optional[int]			=     intra_bottleneck_size
										else:
																snake_case							:  Optional[int]			=     hidden_size

										snake_case							:  Optional[Any]			=     classifier_dropout




class     a (					__magic_name__     ):




				@property
				def 						__snake_case				(				self						:					List[str]   ):
										if self.task == "multiple-choice":
																snake_case							:  Any			=     {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
										else:
																snake_case							:  List[str]			=     {0: '''batch''', 1: '''sequence'''}
										return OrderedDict(
										    [
										        ('''input_ids''', dynamic_axis),
										        ('''attention_mask''', dynamic_axis),
										        ('''token_type_ids''', dynamic_axis),
										    ]   )



import math
from collections import OrderedDict

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

from .utils import logging


UpperCAmelCase__						:	Any	     = logging.get_logger(__name__)






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def __init__(   self	:				List[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 					__magic_name__							(   self	:				Any     ,     lowerCAmelCase_	:				Tensor	):

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






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def 					__magic_name__							(   self	:				Tuple     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi	) * (input + 0.044715 * torch.pow(lowerCAmelCase_     ,     3.0	))	))






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def __init__(   self	:				Tuple     ,     lowerCAmelCase_	:				bool = False	):

      """simple docstring"""
      super().__init__()
      if use_gelu_python:
         _A:    Union[str, Any]						     =			self._gelu_python
      else:
         _A:    Union[str, Any]						     =			nn.functional.gelu


   def 					__magic_name__							(   self	:				Union[str, Any]     ,     lowerCAmelCase_	:				Tensor	):

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


   def 					__magic_name__							(   self	:				Any     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return self.act(lowerCAmelCase_	)






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def 					__magic_name__							(   self	:				Optional[int]     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return 0.5 * input * (1.0 + torch.tanh(input * 0.7978845608 * (1.0 + 0.044715 * input * input)	))






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def 					__magic_name__							(   self	:				Optional[int]     ,     lowerCAmelCase_	:				Tensor	):

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






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def __init__(   self	:				str     ,     lowerCAmelCase_	:				float     ,     lowerCAmelCase_	:				float	):

      """simple docstring"""
      if min > max:
         raise ValueError(F"""min should be < max (got min: {min}, max: {max})"""	)

      super().__init__()
      _A:    Tuple						     =			min
      _A:    str						     =			max


   def 					__magic_name__							(   self	:				int     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return torch.clip(gelu(lowerCAmelCase_	)     ,     self.min     ,     self.max	)






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def __init__(   self	:				Optional[Any]	):

      """simple docstring"""
      super().__init__()
      _A:    Any						     =			math.sqrt(2 / math.pi	)


   def 					__magic_name__							(   self	:				Union[str, Any]     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.044715 * torch.pow(lowerCAmelCase_     ,     3	))	))






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def 					__magic_name__							(   self	:				str     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return nn.functional.silu(lowerCAmelCase_	)






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def __init__(   self	:				Union[str, Any]	):

      """simple docstring"""
      super().__init__()
      if version.parse(torch.__version__	) < version.parse('''1.9.0'''	):
         _A:    Optional[Any]						     =			self._mish_python
      else:
         _A:    int						     =			nn.functional.mish


   def 					__magic_name__							(   self	:				Optional[int]     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return input * torch.tanh(nn.functional.softplus(lowerCAmelCase_	)	)


   def 					__magic_name__							(   self	:				Any     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return self.act(lowerCAmelCase_	)






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def 					__magic_name__							(   self	:				Tuple     ,     lowerCAmelCase_	:				Tensor	):

      """simple docstring"""
      return input






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def 					__magic_name__							(   self	:				Dict     ,     lowerCAmelCase_	:				List[str]     ,     lowerCAmelCase_	:				Tuple=0.707107     ,     lowerCAmelCase_	:				Union[str, Any]=0.282095	):

      """simple docstring"""
      _A:    Any						     =			(input - mu).div(sigma * math.sqrt(2.0	)	)
      return 0.5 * (1.0 + torch.erf(lowerCAmelCase_	))






class UpperCAmelCase  (		nn.Module  ):





   '''simple docstring'''


   def 					__magic_name__							(   self	:				Union[str, Any]     ,     lowerCAmelCase_	:				List[Any]	):

      """simple docstring"""
      _A:    Optional[int]						     =			nn.functional.relu(lowerCAmelCase_	)
      _A:    Any						     =			torch.square(lowerCAmelCase_	)
      return squared






class UpperCAmelCase  (		SCREAMING_SNAKE_CASE__  ):





   '''simple docstring'''


   def __getitem__(   self	:				List[Any]     ,     lowerCAmelCase_	:				Tuple	):

      """simple docstring"""
      _A:    Any						     =			super().__getitem__(lowerCAmelCase_	)
      _A     ,    _A:    List[str]						     =			content if isinstance(lowerCAmelCase_     ,     lowerCAmelCase_	) else (content, {})
      return cls(**lowerCAmelCase_	)

UpperCAmelCase__						:	List[str]	     = {
    '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,
}
UpperCAmelCase__						:	List[str]	     = ClassInstantier(ACTaCLS)






def     lowerCamelCase__				(   a ) ->  List[str]:
   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
UpperCAmelCase__						:	Any	     = get_activation('gelu_python')
UpperCAmelCase__						:	Dict	     = get_activation('gelu_new')
UpperCAmelCase__						:	List[Any]	     = get_activation('gelu')
UpperCAmelCase__						:	Dict	     = get_activation('gelu_fast')
UpperCAmelCase__						:	str	     = get_activation('quick_gelu')
UpperCAmelCase__						:	Union[str, Any]	     = get_activation('silu')
UpperCAmelCase__						:	List[Any]	     = get_activation('mish')





UpperCAmelCase__						:	int	     = get_activation('linear')



