



"""simple docstring"""







from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import SwinConfig
from transformers.testing_utils import require_tf, require_vision, slow, to_atuple
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers.models.swin.modeling_tf_swin import (
			    TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
			    TFSwinForImageClassification,
			    TFSwinForMaskedImageModeling,
			    TFSwinModel,
			)


if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor

class 			_a     :



			def __init__( self       :							Union[str, Any]      ,  _lowercase       :							List[str]      ,  _lowercase       :							Optional[Any]=13      ,  _lowercase       :							List[Any]=32      ,  _lowercase       :							str=2      ,  _lowercase       :							List[str]=3      ,  _lowercase       :							int=16      ,  _lowercase       :							str=[1, 2, 1]      ,  _lowercase       :							Optional[Any]=[2, 2, 4]      ,  _lowercase       :							Dict=2      ,  _lowercase       :							Any=2.0      ,  _lowercase       :							int=True      ,  _lowercase       :							str=0.0      ,  _lowercase       :							int=0.0      ,  _lowercase       :							Union[str, Any]=0.1      ,  _lowercase       :							Union[str, Any]="gelu"      ,  _lowercase       :							Dict=False      ,  _lowercase       :							str=True      ,  _lowercase       :							Union[str, Any]=0.02      ,  _lowercase       :							List[str]=1E-5      ,  _lowercase       :							Tuple=True      ,  _lowercase       :							str=None      ,  _lowercase       :							Any=True      ,  _lowercase       :							str=10      ,  _lowercase       :							int=8      ,  )       ->				None:
									snake_case      : Any							=   parent
									snake_case      : Union[str, Any]							=   batch_size
									snake_case      : int							=   image_size
									snake_case      : List[Any]							=   patch_size
									snake_case      : Optional[int]							=   num_channels
									snake_case      : int							=   embed_dim
									snake_case      : Any							=   depths
									snake_case      : Dict							=   num_heads
									snake_case      : Any							=   window_size
									snake_case      : List[str]							=   mlp_ratio
									snake_case      : List[str]							=   qkv_bias
									snake_case      : Optional[int]							=   hidden_dropout_prob
									snake_case      : Tuple							=   attention_probs_dropout_prob
									snake_case      : Union[str, Any]							=   drop_path_rate
									snake_case      : Dict							=   hidden_act
									snake_case      : List[str]							=   use_absolute_embeddings
									snake_case      : Dict							=   patch_norm
									snake_case      : Dict							=   layer_norm_eps
									snake_case      : Optional[int]							=   initializer_range
									snake_case      : List[Any]							=   is_training
									snake_case      : List[Any]							=   scope
									snake_case      : Optional[Any]							=   use_labels
									snake_case      : int							=   type_sequence_label_size
									snake_case      : Optional[int]							=   encoder_stride



			def 							__lowercase				( self       :							Dict		)       ->				List[Any]:
									snake_case      : Tuple							=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

									snake_case      : List[Any]							=   None
									if self.use_labels:
															snake_case      : Any							=   ids_tensor([self.batch_size]      ,  self.type_sequence_label_size		)

									snake_case      : Optional[int]							=   self.get_config()

									return config, pixel_values, labels



			def 							__lowercase				( self       :							Dict		)       ->				Optional[Any]:
									return SwinConfig(
									    image_size=self.image_size      ,  patch_size=self.patch_size      ,  num_channels=self.num_channels      ,  embed_dim=self.embed_dim      ,  depths=self.depths      ,  num_heads=self.num_heads      ,  window_size=self.window_size      ,  mlp_ratio=self.mlp_ratio      ,  qkv_bias=self.qkv_bias      ,  hidden_dropout_prob=self.hidden_dropout_prob      ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,  drop_path_rate=self.drop_path_rate      ,  hidden_act=self.hidden_act      ,  use_absolute_embeddings=self.use_absolute_embeddings      ,  path_norm=self.patch_norm      ,  layer_norm_eps=self.layer_norm_eps      ,  initializer_range=self.initializer_range      ,  encoder_stride=self.encoder_stride      ,  )



			def 							__lowercase				( self       :							Any      ,  _lowercase       :							Tuple      ,  _lowercase       :							Tuple      ,  _lowercase       :							Optional[int]		)       ->				Dict:
									snake_case      : Union[str, Any]							=   TFSwinModel(config=_lowercase		)
									snake_case      : Tuple							=   model(_lowercase		)

									snake_case      : Any							=   ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths		) - 1))
									snake_case      : Any							=   int(config.embed_dim * 2 ** (len(config.depths		) - 1)		)

									self.parent.assertEqual(result.last_hidden_state.shape      ,  (self.batch_size, expected_seq_len, expected_dim)		)



			def 							__lowercase				( self       :							Dict      ,  _lowercase       :							Optional[int]      ,  _lowercase       :							Any      ,  _lowercase       :							List[Any]		)       ->				List[Any]:
									snake_case      : Any							=   TFSwinForMaskedImageModeling(config=_lowercase		)
									snake_case      : List[str]							=   model(_lowercase		)
									self.parent.assertEqual(
									    result.logits.shape      ,  (self.batch_size, self.num_channels, self.image_size, self.image_size)		)

									# test greyscale images
									snake_case      : Optional[Any]							=   1
									snake_case      : Optional[int]							=   TFSwinForMaskedImageModeling(_lowercase		)

									snake_case      : Tuple							=   floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
									snake_case      : Tuple							=   model(_lowercase		)
									self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, 1, self.image_size, self.image_size)		)



			def 							__lowercase				( self       :							List[str]      ,  _lowercase       :							Union[str, Any]      ,  _lowercase       :							List[Any]      ,  _lowercase       :							str		)       ->				Optional[Any]:
									snake_case      : List[Any]							=   self.type_sequence_label_size
									snake_case      : Optional[Any]							=   TFSwinForImageClassification(_lowercase		)
									snake_case      : Optional[Any]							=   model(_lowercase      ,  labels=_lowercase		)
									self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.type_sequence_label_size)		)

									# test greyscale images
									snake_case      : Dict							=   1
									snake_case      : int							=   TFSwinForImageClassification(_lowercase		)
									snake_case      : Optional[Any]							=   floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
									snake_case      : List[Any]							=   model(_lowercase		)
									self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.type_sequence_label_size)		)



			def 							__lowercase				( self       :							List[str]		)       ->				Optional[Any]:
									snake_case      : Union[str, Any]							=   self.prepare_config_and_inputs()
									snake_case						, snake_case						, snake_case      : List[Any]							=   config_and_inputs
									snake_case      : Any							=   {"pixel_values": pixel_values}
									return config, inputs_dict



@require_tf
class 			_a     (   SCREAMING_SNAKE_CASE__    ,  SCREAMING_SNAKE_CASE__    ,  unittest.TestCase):
			__magic_name__    				=    (
			    (
			        TFSwinModel,
			        TFSwinForImageClassification,
			        TFSwinForMaskedImageModeling,
			    )
			    if is_tf_available()
			    else ()
			)
			__magic_name__    				=    (
			    {"""feature-extraction""": TFSwinModel, """image-classification""": TFSwinForImageClassification}
			    if is_tf_available()
			    else {}
			)

			__magic_name__    				=    False
			__magic_name__    				=    False
			__magic_name__    				=    False
			__magic_name__    				=    False



			def 							__lowercase				( self       :							Dict		)       ->				Dict:
									snake_case      : Dict							=   TFSwinModelTester(self		)
									snake_case      : List[Any]							=   ConfigTester(self      ,  config_class=_lowercase      ,  embed_dim=37		)



			def 							__lowercase				( self       :							int		)       ->				str:
									self.create_and_test_config_common_properties()
									self.config_tester.create_and_test_config_to_json_string()
									self.config_tester.create_and_test_config_to_json_file()
									self.config_tester.create_and_test_config_from_and_save_pretrained()
									self.config_tester.create_and_test_config_with_num_labels()
									self.config_tester.check_config_can_be_init_without_params()
									self.config_tester.check_config_arguments_init()



			def 							__lowercase				( self       :							Tuple		)       ->				Tuple:
									return



			def 							__lowercase				( self       :							List[str]		)       ->				Union[str, Any]:
									snake_case      : Optional[Any]							=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_lowercase		)



			def 							__lowercase				( self       :							Union[str, Any]		)       ->				str:
									snake_case      : List[Any]							=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_image_modeling(*_lowercase		)



			def 							__lowercase				( self       :							Optional[int]		)       ->				Optional[Any]:
									snake_case      : Optional[Any]							=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*_lowercase		)



			@unittest.skip(reason="Swin does not use inputs_embeds"		)
			def 							__lowercase				( self       :							Dict		)       ->				List[str]:
									pass



			def 							__lowercase				( self       :							Optional[Any]		)       ->				Union[str, Any]:
									snake_case						, snake_case      : str							=   self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
															snake_case      : int							=   model_class(_lowercase		)
															self.assertIsInstance(model.get_input_embeddings()      ,  tf.keras.layers.Layer		)
															snake_case      : Dict							=   model.get_output_embeddings()
															self.assertTrue(x is None or isinstance(_lowercase      ,  tf.keras.layers.Dense		)		)



			def 							__lowercase				( self       :							Optional[int]		)       ->				str:
									snake_case						, snake_case      : Union[str, Any]							=   self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
															snake_case      : Tuple							=   model_class(_lowercase		)
															snake_case      : Union[str, Any]							=   inspect.signature(model.call		)
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															snake_case      : Any							=   [*signature.parameters.keys()]

															snake_case      : Dict							=   ["pixel_values"]
															self.assertListEqual(arg_names[:1]      ,  _lowercase		)



			def 							__lowercase				( self       :							List[Any]		)       ->				Optional[int]:
									snake_case						, snake_case      : Dict							=   self.model_tester.prepare_config_and_inputs_for_common()
									snake_case      : Union[str, Any]							=   True

									for model_class in self.all_model_classes:
															snake_case      : Dict							=   True
															snake_case      : Union[str, Any]							=   False
															snake_case      : Dict							=   True
															snake_case      : List[str]							=   model_class(_lowercase		)
															snake_case      : str							=   model(**self._prepare_for_class(_lowercase      ,  _lowercase		)		)
															snake_case      : str							=   outputs.attentions
															snake_case      : str							=   len(self.model_tester.depths		)
															self.assertEqual(len(_lowercase		)      ,  _lowercase		)

															# check that output_attentions also work using config
															del inputs_dict["output_attentions"]
															snake_case      : Union[str, Any]							=   True
															snake_case      : str							=   config.window_size**2
															snake_case      : List[str]							=   model_class(_lowercase		)
															snake_case      : Union[str, Any]							=   model(**self._prepare_for_class(_lowercase      ,  _lowercase		)		)
															snake_case      : Optional[Any]							=   outputs.attentions
															self.assertEqual(len(_lowercase		)      ,  _lowercase		)

															self.assertListEqual(
															    list(attentions[0].shape[-3:]		)      ,  [self.model_tester.num_heads[0], window_size_squared, window_size_squared]      ,  )
															snake_case      : Optional[int]							=   len(_lowercase		)

															# Check attention is always last and order is fine
															snake_case      : Union[str, Any]							=   True
															snake_case      : Optional[int]							=   True
															snake_case      : Optional[int]							=   model_class(_lowercase		)
															snake_case      : Union[str, Any]							=   model(**self._prepare_for_class(_lowercase      ,  _lowercase		)		)

															if hasattr(self.model_tester      ,  "num_hidden_states_types"		):
																					snake_case      : List[str]							=   self.model_tester.num_hidden_states_types
															else:
																					# also another +1 for reshaped_hidden_states
																					snake_case      : Dict							=   2
															self.assertEqual(out_len + added_hidden_states      ,  len(_lowercase		)		)

															snake_case      : Dict							=   outputs.attentions

															self.assertEqual(len(_lowercase		)      ,  _lowercase		)

															self.assertListEqual(
															    list(self_attentions[0].shape[-3:]		)      ,  [self.model_tester.num_heads[0], window_size_squared, window_size_squared]      ,  )



			def 							__lowercase				( self       :							Optional[int]      ,  _lowercase       :							str      ,  _lowercase       :							Union[str, Any]      ,  _lowercase       :							int      ,  _lowercase       :							List[str]		)       ->				Any:
									snake_case      : Dict							=   model_class(_lowercase		)
									snake_case      : Dict							=   model(**self._prepare_for_class(_lowercase      ,  _lowercase		)		)
									snake_case      : List[str]							=   outputs.hidden_states

									snake_case      : Dict							=   getattr(
									    self.model_tester      ,  "expected_num_hidden_layers"      ,  len(self.model_tester.depths		) + 1		)
									self.assertEqual(len(_lowercase		)      ,  _lowercase		)

									# Swin has a different seq_length
									snake_case      : Optional[Any]							=   to_atuple(config.patch_size		)

									snake_case      : Dict							=   (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

									self.assertListEqual(
									    list(hidden_states[0].shape[-2:]		)      ,  [num_patches, self.model_tester.embed_dim]      ,  )

									snake_case      : Optional[Any]							=   outputs.reshaped_hidden_states
									self.assertEqual(len(_lowercase		)      ,  _lowercase		)

									snake_case						, snake_case						, snake_case						, snake_case      : Dict							=   reshaped_hidden_states[0].shape

									snake_case      : str							=   tf.reshape(reshaped_hidden_states[0]      ,  (batch_size, num_channels, height * width)		)
									snake_case      : int							=   tf.transpose(_lowercase      ,  (0, 2, 1)		)

									self.assertListEqual(
									    list(reshaped_hidden_states.shape[-2:]		)      ,  [num_patches, self.model_tester.embed_dim]      ,  )



			def 							__lowercase				( self       :							List[str]		)       ->				Optional[int]:
									snake_case						, snake_case      : List[str]							=   self.model_tester.prepare_config_and_inputs_for_common()

									snake_case      : Tuple							=   to_atuple(self.model_tester.image_size		)

									for model_class in self.all_model_classes:
															snake_case      : List[str]							=   True
															self.check_hidden_states_output(_lowercase      ,  _lowercase      ,  _lowercase      ,  _lowercase		)

															# check that output_hidden_states also work using config
															del inputs_dict["output_hidden_states"]
															snake_case      : int							=   True

															self.check_hidden_states_output(_lowercase      ,  _lowercase      ,  _lowercase      ,  _lowercase		)



			def 							__lowercase				( self       :							Any		)       ->				Optional[int]:
									snake_case						, snake_case      : Any							=   self.model_tester.prepare_config_and_inputs_for_common()
									snake_case      : Optional[Any]							=   3

									snake_case      : Union[str, Any]							=   to_atuple(self.model_tester.image_size		)
									snake_case      : List[Any]							=   to_atuple(config.patch_size		)

									snake_case      : str							=   image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
									snake_case      : Union[str, Any]							=   image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

									for model_class in self.all_model_classes:
															snake_case      : Any							=   True
															self.check_hidden_states_output(_lowercase      ,  _lowercase      ,  _lowercase      ,  (padded_height, padded_width)		)

															# check that output_hidden_states also work using config
															del inputs_dict["output_hidden_states"]
															snake_case      : Optional[int]							=   True
															self.check_hidden_states_output(_lowercase      ,  _lowercase      ,  _lowercase      ,  (padded_height, padded_width)		)



			@slow
			def 							__lowercase				( self       :							Union[str, Any]		)       ->				int:
									for model_name in TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															snake_case      : Union[str, Any]							=   TFSwinModel.from_pretrained(_lowercase		)
															self.assertIsNotNone(_lowercase		)



@require_vision
@require_tf
class 			_a     (   unittest.TestCase):



			@cached_property
			def 							__lowercase				( self       :							Union[str, Any]		)       ->				Tuple:
									return (
									    AutoImageProcessor.from_pretrained("microsoft/swin-tiny-patch4-window7-224"		)
									    if is_vision_available()
									    else None
									)



			@slow
			def 							__lowercase				( self       :							Union[str, Any]		)       ->				int:
									snake_case      : int							=   TFSwinForImageClassification.from_pretrained("microsoft/swin-tiny-patch4-window7-224"		)
									snake_case      : List[str]							=   self.default_image_processor

									snake_case      : List[Any]							=   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
									snake_case      : Optional[int]							=   image_processor(images=_lowercase      ,  return_tensors="tf"		)

									# forward pass
									snake_case      : Union[str, Any]							=   model(_lowercase		)

									# verify the logits
									snake_case      : str							=   tf.TensorShape((1, 1000)		)
									self.assertEqual(outputs.logits.shape      ,  _lowercase		)
									snake_case      : Dict							=   tf.constant([-0.0948, -0.6454, -0.0921]		)
									self.assertTrue(np.allclose(outputs.logits[0, :3]      ,  _lowercase      ,  atol=1E-4		)		)








"""simple docstring"""







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



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



class 			_a     (   nn.Module):



			def 							__lowercase				( self       :							Tuple      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi		) * (input + 0.044715 * torch.pow(_lowercase      ,  3.0		))		))



class 			_a     (   nn.Module):



			def __init__( self       :							Tuple      ,  _lowercase       :							bool = False		)       ->				Optional[Any]:
									super().__init__()
									if use_gelu_python:
															snake_case      : Tuple							=   self._gelu_python
									else:
															snake_case      : Any							=   nn.functional.gelu



			def 							__lowercase				( self       :							Any      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0		)		))



			def 							__lowercase				( self       :							Optional[int]      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return self.act(_lowercase		)



class 			_a     (   nn.Module):



			def 							__lowercase				( self       :							Union[str, Any]      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return 0.5 * input * (1.0 + torch.tanh(input * 0.7978845608 * (1.0 + 0.044715 * input * input)		))



class 			_a     (   nn.Module):



			def 							__lowercase				( self       :							Dict      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return input * torch.sigmoid(1.702 * input		)



class 			_a     (   nn.Module):



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

									super().__init__()
									snake_case      : str							=   min
									snake_case      : Dict							=   max



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



class 			_a     (   nn.Module):



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



			def 							__lowercase				( self       :							Union[str, Any]      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.044715 * torch.pow(_lowercase      ,  3		))		))



class 			_a     (   nn.Module):



			def 							__lowercase				( self       :							int      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return nn.functional.silu(_lowercase		)



class 			_a     (   nn.Module):



			def __init__( self       :							Union[str, Any]		)       ->				Optional[Any]:
									super().__init__()
									if version.parse(torch.__version__		) < version.parse("1.9.0"		):
															snake_case      : Union[str, Any]							=   self._mish_python
									else:
															snake_case      : Union[str, Any]							=   nn.functional.mish



			def 							__lowercase				( self       :							str      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return input * torch.tanh(nn.functional.softplus(_lowercase		)		)



			def 							__lowercase				( self       :							Tuple      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return self.act(_lowercase		)



class 			_a     (   nn.Module):



			def 							__lowercase				( self       :							List[Any]      ,  _lowercase       :							Tensor		)       ->				Tensor:
									return input



class 			_a     (   nn.Module):



			def 							__lowercase				( self       :							Optional[Any]      ,  _lowercase       :							Optional[Any]      ,  _lowercase       :							List[str]=0.707107      ,  _lowercase       :							Dict=0.282095		)       ->				int:
									snake_case      : Any							=   (input - mu).div(sigma * math.sqrt(2.0		)		)
									return 0.5 * (1.0 + torch.erf(_lowercase		))



class 			_a     (   nn.Module):



			def 							__lowercase				( self       :							str      ,  _lowercase       :							List[str]		)       ->				str:
									snake_case      : Optional[Any]							=   nn.functional.relu(_lowercase		)
									snake_case      : List[str]							=   torch.square(_lowercase		)
									return squared



class 			_a     (   SCREAMING_SNAKE_CASE__):



			def __getitem__( self       :							List[str]      ,  _lowercase       :							Any		)       ->				int:
									snake_case      : List[str]							=   super().__getitem__(_lowercase		)
									snake_case						, snake_case      : Optional[Any]							=   content if isinstance(_lowercase      ,  _lowercase		) else (content, {})
									return cls(**_lowercase		)



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    __SCREAMING_SNAKE_CASE		( lowerCamelCase_:       Tuple   ):
						"""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')



