


from __future__ import annotations

import copy
import inspect
import json
import math
import os
import tempfile
import unittest
from importlib import import_module

import numpy as np

from transformers import ViTMAEConfig
from transformers.file_utils import cached_property, is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, require_vision, slow

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 import TFViTMAEForPreTraining, TFViTMAEModel


if is_vision_available():
   from PIL import Image

   from transformers import ViTImageProcessor
class 			SCREAMING_SNAKE_CASE__  :
      def __init__(	self    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	List[Any]=1_3					,							SCREAMING_SNAKE_CASE__    :	List[Any]=3_0					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=2					,							SCREAMING_SNAKE_CASE__    :	List[Any]=3					,							SCREAMING_SNAKE_CASE__    :	List[Any]=True					,							SCREAMING_SNAKE_CASE__    :	List[str]=True					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=3_2					,							SCREAMING_SNAKE_CASE__    :	Optional[int]=2					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=4					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=3_7					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]="gelu"					,							SCREAMING_SNAKE_CASE__    :	Dict=0.1					,							SCREAMING_SNAKE_CASE__    :	List[str]=0.1					,							SCREAMING_SNAKE_CASE__    :	List[str]=1_0					,							SCREAMING_SNAKE_CASE__    :	Dict=0.02					,							SCREAMING_SNAKE_CASE__    :	Any=3					,							SCREAMING_SNAKE_CASE__    :	int=0.6					,							SCREAMING_SNAKE_CASE__    :	Any=None					,							)		->      Union[str, Any]:
             a_ :		Any							=  parent
             a_ :		Any							=  batch_size
             a_ :		List[Any]							=  image_size
             a_ :		List[str]							=  patch_size
             a_ :		Dict							=  num_channels
             a_ :		int							=  is_training
             a_ :		int							=  use_labels
             a_ :		Union[str, Any]							=  hidden_size
             a_ :		Optional[Any]							=  num_hidden_layers
             a_ :		Any							=  num_attention_heads
             a_ :		Union[str, Any]							=  intermediate_size
             a_ :		Union[str, Any]							=  hidden_act
             a_ :		Union[str, Any]							=  hidden_dropout_prob
             a_ :		List[Any]							=  attention_probs_dropout_prob
             a_ :		Union[str, Any]							=  type_sequence_label_size
             a_ :		Any							=  initializer_range
             a_ :		List[str]							=  mask_ratio
             a_ :		Dict							=  scope

             # in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
             # (we add 1 for the [CLS] token)
             a_ :		Tuple							=  (image_size // patch_size) ** 2
             a_ :		Dict							=  int(math.ceil((1 - mask_ratio) * (num_patches + 1)					)					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      Any:
             a_ :		Any							=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

             a_ :		Optional[Any]							=  None
             if self.use_labels:
                    a_ :		Dict							=  ids_tensor([self.batch_size]					,							self.type_sequence_label_size					)

             a_ :		Union[str, Any]							=  self.get_config()

             return config, pixel_values, labels
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[Any]					)		->      Any:
             return ViTMAEConfig(
                 image_size=self.image_size					,							patch_size=self.patch_size					,							num_channels=self.num_channels					,							hidden_size=self.hidden_size					,							num_hidden_layers=self.num_hidden_layers					,							num_attention_heads=self.num_attention_heads					,							intermediate_size=self.intermediate_size					,							decoder_hidden_size=self.hidden_size					,							decoder_num_hidden_layers=self.num_hidden_layers					,							decoder_num_attention_heads=self.num_attention_heads					,							decoder_intermediate_size=self.intermediate_size					,							hidden_act=self.hidden_act					,							hidden_dropout_prob=self.hidden_dropout_prob					,							attention_probs_dropout_prob=self.attention_probs_dropout_prob					,							is_decoder=SCREAMING_SNAKE_CASE__					,							initializer_range=self.initializer_range					,							mask_ratio=self.mask_ratio					,							)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	int					)		->      Union[str, Any]:
             a_ :		Any							=  TFViTMAEModel(config=SCREAMING_SNAKE_CASE__					)
             a_ :		Union[str, Any]							=  model(SCREAMING_SNAKE_CASE__					,							training=SCREAMING_SNAKE_CASE__					)
             self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	Dict					)		->      List[str]:
             a_ :		List[Any]							=  TFViTMAEForPreTraining(SCREAMING_SNAKE_CASE__					)
             a_ :		Any							=  model(SCREAMING_SNAKE_CASE__					,							training=SCREAMING_SNAKE_CASE__					)
             # expected sequence length = num_patches
             a_ :		Union[str, Any]							=  (self.image_size // self.patch_size) ** 2
             a_ :		List[str]							=  self.patch_size**2 * self.num_channels
             self.parent.assertEqual(result.logits.shape					,							(self.batch_size, num_patches, expected_num_channels)					)

             # test greyscale images
             a_ :		Tuple							=  1
             a_ :		Any							=  TFViTMAEForPreTraining(SCREAMING_SNAKE_CASE__					)

             a_ :		Union[str, Any]							=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
             a_ :		Optional[Any]							=  model(SCREAMING_SNAKE_CASE__					,							training=SCREAMING_SNAKE_CASE__					)
             a_ :		Tuple							=  self.patch_size**2
             self.parent.assertEqual(result.logits.shape					,							(self.batch_size, num_patches, expected_num_channels)					)

      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      int:
             a_ :		Optional[Any]							=  self.prepare_config_and_inputs()
             ((a_)							,		(a_)							,		(a_)) :		Any							=  config_and_inputs
             a_ :		List[str]							=  {'pixel_values': pixel_values}
             return config, inputs_dict
@require_tf
class 			SCREAMING_SNAKE_CASE__  (    lowercase__						,   lowercase__						,   unittest.TestCase      ):
      snake_case__    :					Optional[Any]					       =						(TFViTMAEModel, TFViTMAEForPreTraining) if is_tf_available() else ()
      snake_case__    :					List[str]					       =						{'''feature-extraction''': TFViTMAEModel} if is_tf_available() else {}

      snake_case__    :					Union[str, Any]					       =						False
      snake_case__    :					Tuple					       =						False
      snake_case__    :					str					       =						False
      snake_case__    :					Union[str, Any]					       =						False
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      Dict:
             a_ :		List[str]							=  TFViTMAEModelTester(self					)
             a_ :		Any							=  ConfigTester(self					,							config_class=SCREAMING_SNAKE_CASE__					,							has_text_modality=SCREAMING_SNAKE_CASE__					,							hidden_size=3_7					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      Tuple:
             self.config_tester.run_common_tests()
      @unittest.skip(reason='ViTMAE does not use inputs_embeds'					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					)		->      Optional[int]:
             pass
      def 	SCREAMING_SNAKE_CASE							(	self    :	int					)		->      List[str]:
             a_							,		a_ :		List[str]							=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    a_ :		Optional[Any]							=  model_class(SCREAMING_SNAKE_CASE__					)
                    self.assertIsInstance(model.get_input_embeddings()					,							(tf.keras.layers.Layer)					)
                    a_ :		str							=  model.get_output_embeddings()
                    self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE__					,							tf.keras.layers.Layer					)					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      Optional[Any]:
             a_							,		a_ :		Union[str, Any]							=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    a_ :		Tuple							=  model_class(SCREAMING_SNAKE_CASE__					)
                    a_ :		List[Any]							=  inspect.signature(model.call					)
                    # signature.parameters is an OrderedDict => so arg_names order is deterministic
                    a_ :		Tuple							=  [*signature.parameters.keys()]

                    a_ :		int							=  ['pixel_values']
                    self.assertListEqual(arg_names[:1]					,							SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	int					)		->      Optional[Any]:
             a_ :		Any							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[Any]					)		->      List[str]:
             a_ :		Optional[int]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Any					)		->      Union[str, Any]:
             # make the mask reproducible
             np.random.seed(2					)

             a_							,		a_ :		Union[str, Any]							=  self.model_tester.prepare_config_and_inputs_for_common()

             a_ :		Union[str, Any]							=  int((config.image_size // config.patch_size) ** 2					)
             a_ :		Optional[int]							=  np.random.uniform(size=(self.model_tester.batch_size, num_patches)					)

             for model_class in self.all_model_classes:
                    a_ :		str							=  model_class(SCREAMING_SNAKE_CASE__					)
                    a_ :		List[Any]							=  self._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)

                    a_ :		int							=  model(SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)

                    a_ :		Any							=  copy.deepcopy(self._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)					)
                    a_ :		List[str]							=  model(**SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)
                    a_ :		Optional[Any]							=  outputs_dict[0].numpy()
                    a_ :		Tuple							=  outputs_keywords[0].numpy()

                    self.assertLess(np.sum(np.abs(output_dict - output_keywords					)					)					,							1E-6					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Any					)		->      int:
             # make the mask reproducible
             np.random.seed(2					)

             a_							,		a_ :		Dict							=  self.model_tester.prepare_config_and_inputs_for_common()

             a_ :		Tuple							=  int((config.image_size // config.patch_size) ** 2					)
             a_ :		Union[str, Any]							=  np.random.uniform(size=(self.model_tester.batch_size, num_patches)					)

             def prepare_numpy_arrays(SCREAMING_SNAKE_CASE__    :	str					):
                    a_ :		Dict							=  {}
                    for k, v in inputs_dict.items():
                           if tf.is_tensor(SCREAMING_SNAKE_CASE__					):
                                  a_ :		str							=  v.numpy()
                           else:
                                  a_ :		Dict							=  np.array(SCREAMING_SNAKE_CASE__					)

                    return inputs_np_dict

             for model_class in self.all_model_classes:
                    a_ :		Optional[int]							=  model_class(SCREAMING_SNAKE_CASE__					)

                    a_ :		Dict							=  self._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
                    a_ :		Any							=  prepare_numpy_arrays(SCREAMING_SNAKE_CASE__					)

                    a_ :		Optional[int]							=  model(SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)
                    a_ :		Any							=  model(**SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)
                    self.assert_outputs_same(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	str					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	Dict					)		->      str:
             # make masks reproducible
             np.random.seed(2					)

             a_ :		int							=  int((tf_model.config.image_size // tf_model.config.patch_size) ** 2					)
             a_ :		Any							=  np.random.uniform(size=(self.model_tester.batch_size, num_patches)					)
             a_ :		Optional[Any]							=  tf.constant(SCREAMING_SNAKE_CASE__					)

             # Add `noise` argument.
             # PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
             a_ :		Union[str, Any]							=  tf_noise

             super().check_pt_tf_models(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      Dict:
             # make mask reproducible
             np.random.seed(2					)

             a_							,		a_ :		int							=  self.model_tester.prepare_config_and_inputs_for_common()

             a_ :		str							=  {
                 module_member
                 for model_class in self.all_model_classes
                 for module in (import_module(model_class.__module__					),)
                 for module_member_name in dir(SCREAMING_SNAKE_CASE__					)
                 if module_member_name.endswith('MainLayer'					)
                 # This condition is required, since `modeling_tf_clip.py` has 3 classes whose names end with `MainLayer`.
                 and module_member_name[: -len('MainLayer'					)] == model_class.__name__[: -len('Model'					)]
                 for module_member in (getattr(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					),)
                 if isinstance(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
                 and tf.keras.layers.Layer in module_member.__bases__
                 and getattr(SCREAMING_SNAKE_CASE__					,							'_keras_serializable'					,							SCREAMING_SNAKE_CASE__					)
             }

             a_ :		Any							=  int((config.image_size // config.patch_size) ** 2					)
             a_ :		Any							=  np.random.uniform(size=(self.model_tester.batch_size, num_patches)					)
             a_ :		Optional[Any]							=  tf.convert_to_tensor(SCREAMING_SNAKE_CASE__					)
             inputs_dict.update({'noise': noise}					)

             for main_layer_class in tf_main_layer_classes:
                    a_ :		Tuple							=  main_layer_class(SCREAMING_SNAKE_CASE__					)

                    a_ :		Union[str, Any]							=  {
                        name: tf.keras.Input(tensor.shape[1:]					,							dtype=tensor.dtype					) for name, tensor in inputs_dict.items()
                    }

                    a_ :		str							=  tf.keras.Model(SCREAMING_SNAKE_CASE__					,							outputs=main_layer(SCREAMING_SNAKE_CASE__					)					)
                    a_ :		List[Any]							=  model(SCREAMING_SNAKE_CASE__					)

                    with tempfile.TemporaryDirectory() as tmpdirname:
                           a_ :		Optional[int]							=  os.path.join(SCREAMING_SNAKE_CASE__					,							'keras_model.h5'					)
                           model.save(SCREAMING_SNAKE_CASE__					)
                           a_ :		Optional[int]							=  tf.keras.models.load_model(
                               SCREAMING_SNAKE_CASE__					,							custom_objects={main_layer_class.__name__: main_layer_class}					)
                           assert isinstance(SCREAMING_SNAKE_CASE__					,							tf.keras.Model					)
                           a_ :		Any							=  model(SCREAMING_SNAKE_CASE__					)
                           self.assert_outputs_same(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
      @slow
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      str:
             # make mask reproducible
             np.random.seed(2					)

             a_							,		a_ :		List[Any]							=  self.model_tester.prepare_config_and_inputs_for_common()

             a_ :		Any							=  int((config.image_size // config.patch_size) ** 2					)
             a_ :		Optional[Any]							=  np.random.uniform(size=(self.model_tester.batch_size, num_patches)					)

             for model_class in self.all_model_classes:
                    a_ :		Union[str, Any]							=  model_class(SCREAMING_SNAKE_CASE__					)
                    a_ :		str							=  self._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
                    a_ :		int							=  model(SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)

                    if model_class.__name__ == "TFViTMAEModel":
                           a_ :		Tuple							=  outputs.last_hidden_state.numpy()
                           a_ :		List[str]							=  0
                    else:
                           a_ :		Tuple							=  outputs.logits.numpy()
                           a_ :		Optional[int]							=  0

                    with tempfile.TemporaryDirectory() as tmpdirname:
                           model.save_pretrained(SCREAMING_SNAKE_CASE__					,							saved_model=SCREAMING_SNAKE_CASE__					)
                           a_ :		Dict							=  model_class.from_pretrained(SCREAMING_SNAKE_CASE__					)
                           a_ :		Any							=  model(SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)

                           if model_class.__name__ == "TFViTMAEModel":
                                  a_ :		Tuple							=  after_outputs['last_hidden_state'].numpy()
                                  a_ :		Tuple							=  0
                           else:
                                  a_ :		Tuple							=  after_outputs['logits'].numpy()
                                  a_ :		Union[str, Any]							=  0

                           a_ :		Tuple							=  np.amax(np.abs(out_a - out_a					)					)
                           self.assertLessEqual(SCREAMING_SNAKE_CASE__					,							1E-5					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      int:
             # make mask reproducible
             np.random.seed(2					)

             a_							,		a_ :		str							=  self.model_tester.prepare_config_and_inputs_for_common()

             a_ :		Optional[int]							=  int((config.image_size // config.patch_size) ** 2					)
             a_ :		str							=  np.random.uniform(size=(self.model_tester.batch_size, num_patches)					)

             for model_class in self.all_model_classes:
                    a_ :		Optional[Any]							=  model_class(SCREAMING_SNAKE_CASE__					)
                    a_ :		Optional[Any]							=  self._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)

                    a_ :		int							=  model(SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)
                    a_ :		Optional[int]							=  model.get_config()
                    # make sure that returned config is jsonifiable, which is required by keras
                    json.dumps(SCREAMING_SNAKE_CASE__					)
                    a_ :		List[Any]							=  model_class.from_config(model.get_config()					)
                    # make sure it also accepts a normal config
                    a_ :		str							=  model_class.from_config(model.config					)
                    a_ :		Optional[int]							=  new_model(SCREAMING_SNAKE_CASE__					)  # Build model
                    new_model.set_weights(model.get_weights()					)
                    a_ :		Union[str, Any]							=  new_model(SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)

                    self.assert_outputs_same(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
      @unittest.skip(
          reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results.'					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					)		->      Tuple:
             pass
      @unittest.skip(reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load'					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Any					)		->      Union[str, Any]:
             pass

      @slow
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      Any:
             a_ :		str							=  TFViTMAEModel.from_pretrained('google/vit-base-patch16-224'					)
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__					)







def 	SCREAMING_SNAKE_CASE_						(      )     ->		Dict:

       """simple docstring"""

       a_ :		Tuple							=  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'    )
       return image
@require_tf
@require_vision
class 			SCREAMING_SNAKE_CASE__  (    unittest.TestCase      ):
      @cached_property
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[Any]					)		->      str:
             return ViTImageProcessor.from_pretrained('facebook/vit-mae-base'					) if is_vision_available() else None

      @slow
      def 	SCREAMING_SNAKE_CASE							(	self    :	int					)		->      List[str]:
             # make random mask reproducible across the PT and TF model
             np.random.seed(2					)

             a_ :		Any							=  TFViTMAEForPreTraining.from_pretrained('facebook/vit-mae-base'					)

             a_ :		str							=  self.default_image_processor
             a_ :		int							=  prepare_img()
             a_ :		Any							=  image_processor(images=SCREAMING_SNAKE_CASE__					,							return_tensors='tf'					)

             # prepare a noise vector that will be also used for testing the TF model
             # (this way we can ensure that the PT and TF models operate on the same inputs)
             a_ :		List[Any]							=  ViTMAEConfig()
             a_ :		Tuple							=  int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2					)
             a_ :		Any							=  np.random.uniform(size=(1, num_patches)					)

             # forward pass
             a_ :		Tuple							=  model(**SCREAMING_SNAKE_CASE__					,							noise=SCREAMING_SNAKE_CASE__					)

             # verify the logits
             a_ :		Union[str, Any]							=  tf.convert_to_tensor([1, 1_9_6, 7_6_8]					)
             self.assertEqual(outputs.logits.shape					,							SCREAMING_SNAKE_CASE__					)

             a_ :		str							=  tf.convert_to_tensor(
                 [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]					)

             tf.debugging.assert_near(outputs.logits[0, :3, :3]					,							SCREAMING_SNAKE_CASE__					,							atol=1E-4					)






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
   import torch

   from transformers.activations import gelu_new, gelu_python, get_activation
@require_torch
class 			SCREAMING_SNAKE_CASE__  (    unittest.TestCase      ):
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      List[str]:
             a_ :		List[str]							=  torch.tensor([-1_0_0, -1, -0.1, 0, 0.1, 1.0, 1_0_0]					)
             a_ :		Union[str, Any]							=  get_activation('gelu'					)
             self.assertTrue(torch.allclose(gelu_python(SCREAMING_SNAKE_CASE__					)					,							torch_builtin(SCREAMING_SNAKE_CASE__					)					)					)
             self.assertFalse(torch.allclose(gelu_python(SCREAMING_SNAKE_CASE__					)					,							gelu_new(SCREAMING_SNAKE_CASE__					)					)					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					)		->      Any:
             a_ :		List[str]							=  torch.tensor([-1_0_0, -1, -0.1, 0, 0.1, 1.0, 1_0_0]					)
             a_ :		Union[str, Any]							=  get_activation('gelu'					)
             a_ :		str							=  get_activation('gelu_10'					)

             a_ :		Tuple							=  torch_builtin(SCREAMING_SNAKE_CASE__					)
             a_ :		str							=  geluaa(SCREAMING_SNAKE_CASE__					)

             a_ :		List[Any]							=  torch.where(y_gelu_aa < 10.0					,							1					,							0					)

             self.assertTrue(torch.max(SCREAMING_SNAKE_CASE__					).item() == 10.0					)
             self.assertTrue(torch.allclose(y_gelu * clipped_mask					,							y_gelu_aa * clipped_mask					)					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      List[Any]:
             get_activation('gelu'					)
             get_activation('gelu_10'					)
             get_activation('gelu_fast'					)
             get_activation('gelu_new'					)
             get_activation('gelu_python'					)
             get_activation('gelu_pytorch_tanh'					)
             get_activation('linear'					)
             get_activation('mish'					)
             get_activation('quick_gelu'					)
             get_activation('relu'					)
             get_activation('sigmoid'					)
             get_activation('silu'					)
             get_activation('swish'					)
             get_activation('tanh'					)
             with self.assertRaises(SCREAMING_SNAKE_CASE__					):
                    get_activation('bogus'					)
             with self.assertRaises(SCREAMING_SNAKE_CASE__					):
                    get_activation(SCREAMING_SNAKE_CASE__					)

      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      str:
             a_ :		Any							=  get_activation('gelu'					)
             a_ :		Any							=  1
             a_ :		int							=  get_activation('gelu'					)
             self.assertEqual(acta.a					,							1					)
             with self.assertRaises(SCREAMING_SNAKE_CASE__					):
                    a_ :		Tuple							=  acta.a


