"""simple docstring"""




import math

import tensorflow as tf
from packaging import version





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	List[str]     )	->				List[Any]:
  _lowerCAmelCase						:	int        =					tf.convert_to_tensor(_lowerCamelCase     )
  _lowerCAmelCase						:	List[Any]        =					0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0     )      ,x.dtype     )     ))

  return x * cdf





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	Optional[Any]     )	->				Optional[Any]:
  _lowerCAmelCase						:	Optional[Any]        =					tf.convert_to_tensor(_lowerCamelCase     )
  _lowerCAmelCase						:	str        =					tf.cast(math.pi      ,x.dtype     )
  _lowerCAmelCase						:	List[Any]        =					tf.cast(0.04_47_15      ,x.dtype     )
  _lowerCAmelCase						:	int        =					0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi     ) * (x + coeff * tf.pow(_lowerCamelCase      ,3     ))     ))

  return x * cdf





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	Union[str, Any]     )	->				Dict:
  _lowerCAmelCase						:	Tuple        =					tf.convert_to_tensor(_lowerCamelCase     )

  return x * tf.tanh(tf.math.softplus(_lowerCamelCase     )     )





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	List[Any]     )	->				Optional[Any]:
  _lowerCAmelCase						:	Optional[int]        =					tf.convert_to_tensor(_lowerCamelCase     )
  _lowerCAmelCase						:	List[Any]        =					tf.cast(0.04_47_15      ,x.dtype     )
  _lowerCAmelCase						:	Tuple        =					tf.cast(0.79_78_84_56_08      ,x.dtype     )

  return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)     ))





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	Dict     )	->				Any:
  _lowerCAmelCase						:	Optional[int]        =					tf.convert_to_tensor(_lowerCamelCase     )
  _lowerCAmelCase						:	Union[str, Any]        =					tf.cast(1.7_02      ,x.dtype     )
  return x * tf.math.sigmoid(coeff * x     )





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	Any     )	->				int:
  return tf.clip_by_value(_gelu(_lowerCamelCase     )      ,-10      ,10     )





def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	List[str]      ,_lowerCamelCase						:	Union[str, Any]=-1     )	->				List[str]:
  _lowerCAmelCase      ,     _lowerCAmelCase						:	List[Any]        =					tf.split(_lowerCamelCase      ,2      ,axis=_lowerCamelCase     )
  return a * tf.math.sigmoid(_lowerCamelCase     )


if version.parse(tf.version.VERSION) >= version.parse('2.4'):





     def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	List[str]     )	->				List[Any]:
       return tf.keras.activations.gelu(_lowerCamelCase      ,approximate=_lowerCamelCase     )

     _a				:		str	   =       tf.keras.activations.gelu






     _a				:		List[Any]	   =       approximate_gelu_wrap
else:
     _a				:		Optional[int]	   =       _gelu
     _a				:		Dict	   =       _gelu_new


_a				:		Optional[Any]	   =       {
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}






def 							SCREAMING_SNAKE_CASE					(      _lowerCamelCase						:	List[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()     )}"     )





"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


_a				:		List[Any]	   =       logging.get_logger(__name__)
class 						__A							(			SCREAMING_SNAKE_CASE_   ,     SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		"maskformer-swin"

     _UpperCamelCase							:      Union[str, Any]		 =		{
         "num_attention_heads": "num_heads",
         "num_hidden_layers": "num_layers",
     }






     def __init__(		self    ,					a__=224    ,					a__=4    ,					a__=3    ,					a__=96    ,					a__=[2, 2, 6, 2]    ,					a__=[3, 6, 12, 24]    ,					a__=7    ,					a__=4.0    ,					a__=True    ,					a__=0.0    ,					a__=0.0    ,					a__=0.1    ,					a__="gelu"    ,					a__=False    ,					a__=0.0_2    ,					a__=1e-5    ,					a__=None    ,					a__=None    ,					**a__    ,					):
       super().__init__(**a__  )

       _lowerCAmelCase						:	Dict        =					image_size
       _lowerCAmelCase						:	List[str]        =					patch_size
       _lowerCAmelCase						:	Any        =					num_channels
       _lowerCAmelCase						:	int        =					embed_dim
       _lowerCAmelCase						:	Optional[Any]        =					depths
       _lowerCAmelCase						:	List[str]        =					len(a__  )
       _lowerCAmelCase						:	List[Any]        =					num_heads
       _lowerCAmelCase						:	Tuple        =					window_size
       _lowerCAmelCase						:	List[Any]        =					mlp_ratio
       _lowerCAmelCase						:	Optional[Any]        =					qkv_bias
       _lowerCAmelCase						:	int        =					hidden_dropout_prob
       _lowerCAmelCase						:	Union[str, Any]        =					attention_probs_dropout_prob
       _lowerCAmelCase						:	Any        =					drop_path_rate
       _lowerCAmelCase						:	Optional[Any]        =					hidden_act
       _lowerCAmelCase						:	Tuple        =					use_absolute_embeddings
       _lowerCAmelCase						:	str        =					layer_norm_eps
       _lowerCAmelCase						:	Any        =					initializer_range
       # we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
       # this indicates the channel dimension after the last stage of the model
       _lowerCAmelCase						:	Union[str, Any]        =					int(embed_dim * 2 ** (len(a__  ) - 1)  )
       _lowerCAmelCase						:	int        =					["""stem"""] + [F"stage{idx}" for idx in range(1    ,					len(a__  ) + 1  )]
       _lowerCAmelCase      ,     _lowerCAmelCase						:	int        =					get_aligned_output_features_output_indices(
           out_features=a__    ,					out_indices=a__    ,					stage_names=self.stage_names  )




