



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       _snake_case				:






   '''simple docstring'''






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


   def       A__    (    self:     Any							)	->      Optional[Any]:
       UpperCAmelCase_     :       str  		=					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

       UpperCAmelCase_     :       Tuple  		=					None
       if self.use_labels:
           UpperCAmelCase_     :       Tuple  		=					ids_tensor([self.batch_size]  ,self.type_sequence_label_size							)

       UpperCAmelCase_     :       str  		=					self.get_config()

       return config, pixel_values, labels


   def       A__    (    self:     Dict							)	->      int:
       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       A__    (    self:     Optional[int]  ,lowerCamelCase_:     List[Any]  ,lowerCamelCase_:     List[str]  ,lowerCamelCase_:     int							)	->      Optional[Any]:
       UpperCAmelCase_     :       Union[str, Any]  		=					TFSwinModel(config=__snake_case							)
       UpperCAmelCase_     :       Optional[Any]  		=					model(__snake_case							)

       UpperCAmelCase_     :       Any  		=					((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths							) - 1))
       UpperCAmelCase_     :       str  		=					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       A__    (    self:     List[Any]  ,lowerCamelCase_:     int  ,lowerCamelCase_:     Tuple  ,lowerCamelCase_:     str							)	->      Optional[Any]:
       UpperCAmelCase_     :       Tuple  		=					TFSwinForMaskedImageModeling(config=__snake_case							)
       UpperCAmelCase_     :       List[Any]  		=					model(__snake_case							)
       self.parent.assertEqual(
           result.logits.shape  ,(self.batch_size, self.num_channels, self.image_size, self.image_size)							)

       # test greyscale images
       UpperCAmelCase_     :       Dict  		=					1
       UpperCAmelCase_     :       List[Any]  		=					TFSwinForMaskedImageModeling(__snake_case							)

       UpperCAmelCase_     :       Tuple  		=					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]							)
       UpperCAmelCase_     :       List[Any]  		=					model(__snake_case							)
       self.parent.assertEqual(result.logits.shape  ,(self.batch_size, 1, self.image_size, self.image_size)							)


   def       A__    (    self:     Any  ,lowerCamelCase_:     Optional[int]  ,lowerCamelCase_:     Any  ,lowerCamelCase_:     Union[str, Any]							)	->      Optional[Any]:
       UpperCAmelCase_     :       Optional[int]  		=					self.type_sequence_label_size
       UpperCAmelCase_     :       List[str]  		=					TFSwinForImageClassification(__snake_case							)
       UpperCAmelCase_     :       Dict  		=					model(__snake_case  ,labels=__snake_case							)
       self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.type_sequence_label_size)							)

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






   def       A__    (    self:     Tuple							)	->      List[Any]:
       UpperCAmelCase_     :       List[str]  		=					self.prepare_config_and_inputs()
       UpperCAmelCase_     :       int  		=					config_and_inputs
       UpperCAmelCase_     :       Optional[Any]  		=					{'''pixel_values''': pixel_values}
       return config, inputs_dict







@require_tf
class       _snake_case				(     snake_case__ ,							snake_case__ ,							unittest.TestCase ):






   '''simple docstring'''






   A__      : int       =						(
       (
           TFSwinModel,
           TFSwinForImageClassification,
           TFSwinForMaskedImageModeling,
       )
       if is_tf_available()
       else ()
   )
   A__      : Any       =						(
       {'feature-extraction': TFSwinModel, 'image-classification': TFSwinForImageClassification}
       if is_tf_available()
       else {}
   )

   A__      : Any       =						False
   A__      : int       =						False
   A__      : Tuple       =						False
   A__      : Optional[Any]       =						False


   def       A__    (    self:     int							)	->      int:
       UpperCAmelCase_     :       int  		=					TFSwinModelTester(self							)
       UpperCAmelCase_     :       Optional[Any]  		=					ConfigTester(self  ,config_class=__snake_case  ,embed_dim=37							)


   def       A__    (    self:     int							)	->      Tuple:
       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       A__    (    self:     List[str]							)	->      Union[str, Any]:
       return


   def       A__    (    self:     List[Any]							)	->      Optional[int]:
       UpperCAmelCase_     :       Optional[int]  		=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__snake_case							)


   def       A__    (    self:     Any							)	->      Tuple:
       UpperCAmelCase_     :       List[Any]  		=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_image_modeling(*__snake_case							)


   def       A__    (    self:     Union[str, Any]							)	->      Any:
       UpperCAmelCase_     :       Optional[int]  		=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*__snake_case							)


   @unittest.skip(reason="""Swin does not use inputs_embeds"""							)
   def       A__    (    self:     Any							)	->      Dict:
       pass


   def       A__    (    self:     Optional[int]							)	->      Dict:
       UpperCAmelCase_     :       List[Any]  		=					self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           UpperCAmelCase_     :       List[Any]  		=					model_class(__snake_case							)
           self.assertIsInstance(model.get_input_embeddings()  ,tf.keras.layers.Layer							)
           UpperCAmelCase_     :       Optional[Any]  		=					model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(__snake_case  ,tf.keras.layers.Dense							)							)


   def       A__    (    self:     str							)	->      List[Any]:
       UpperCAmelCase_     :       List[Any]  		=					self.model_tester.prepare_config_and_inputs_for_common()

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

           UpperCAmelCase_     :       List[Any]  		=					['''pixel_values''']
           self.assertListEqual(arg_names[:1]  ,__snake_case							)


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

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

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

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

           # Check attention is always last and order is fine
           UpperCAmelCase_     :       int  		=					True
           UpperCAmelCase_     :       Optional[Any]  		=					True
           UpperCAmelCase_     :       Optional[int]  		=					model_class(__snake_case							)
           UpperCAmelCase_     :       Tuple  		=					model(**self._prepare_for_class(__snake_case  ,__snake_case							)							)

           if hasattr(self.model_tester  ,"""num_hidden_states_types"""							):
               UpperCAmelCase_     :       Optional[Any]  		=					self.model_tester.num_hidden_states_types
           else:
               # also another +1 for reshaped_hidden_states
               UpperCAmelCase_     :       str  		=					2
           self.assertEqual(out_len + added_hidden_states  ,len(__snake_case							)							)

           UpperCAmelCase_     :       Dict  		=					outputs.attentions

           self.assertEqual(len(__snake_case							)  ,__snake_case							)

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


   def       A__    (    self:     Union[str, Any]  ,lowerCamelCase_:     Optional[int]  ,lowerCamelCase_:     List[str]  ,lowerCamelCase_:     Optional[Any]  ,lowerCamelCase_:     Union[str, Any]							)	->      Any:
       UpperCAmelCase_     :       List[Any]  		=					model_class(__snake_case							)
       UpperCAmelCase_     :       Optional[int]  		=					model(**self._prepare_for_class(__snake_case  ,__snake_case							)							)
       UpperCAmelCase_     :       Optional[Any]  		=					outputs.hidden_states

       UpperCAmelCase_     :       List[Any]  		=					getattr(
           self.model_tester  ,"""expected_num_hidden_layers"""  ,len(self.model_tester.depths							) + 1							)
       self.assertEqual(len(__snake_case							)  ,__snake_case							)

       # Swin has a different seq_length
       UpperCAmelCase_     :       List[str]  		=					to_atuple(config.patch_size							)

       UpperCAmelCase_     :       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]  ,)

       UpperCAmelCase_     :       List[str]  		=					outputs.reshaped_hidden_states
       self.assertEqual(len(__snake_case							)  ,__snake_case							)

       UpperCAmelCase_     :       Optional[int]  		=					reshaped_hidden_states[0].shape

       UpperCAmelCase_     :       Union[str, Any]  		=					tf.reshape(reshaped_hidden_states[0]  ,(batch_size, num_channels, height * width)							)
       UpperCAmelCase_     :       int  		=					tf.transpose(__snake_case  ,(0, 2, 1)							)

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


   def       A__    (    self:     Any							)	->      int:
       UpperCAmelCase_     :       Dict  		=					self.model_tester.prepare_config_and_inputs_for_common()

       UpperCAmelCase_     :       Optional[int]  		=					to_atuple(self.model_tester.image_size							)

       for model_class in self.all_model_classes:
           UpperCAmelCase_     :       Union[str, Any]  		=					True
           self.check_hidden_states_output(__snake_case  ,__snake_case  ,__snake_case  ,__snake_case							)

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

           self.check_hidden_states_output(__snake_case  ,__snake_case  ,__snake_case  ,__snake_case							)


   def       A__    (    self:     Optional[int]							)	->      Optional[Any]:
       UpperCAmelCase_     :       int  		=					self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase_     :       int  		=					3

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

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

       for model_class in self.all_model_classes:
           UpperCAmelCase_     :       Tuple  		=					True
           self.check_hidden_states_output(__snake_case  ,__snake_case  ,__snake_case  ,(padded_height, padded_width)							)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           UpperCAmelCase_     :       str  		=					True
           self.check_hidden_states_output(__snake_case  ,__snake_case  ,__snake_case  ,(padded_height, padded_width)							)






   @slow
   def       A__    (    self:     Optional[int]							)	->      int:
       for model_name in TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           UpperCAmelCase_     :       Any  		=					TFSwinModel.from_pretrained(__snake_case							)
           self.assertIsNotNone(__snake_case							)







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






   '''simple docstring'''






   @cached_property
   def       A__    (    self:     List[Any]							)	->      Optional[Any]:
       return (
           AutoImageProcessor.from_pretrained("""microsoft/swin-tiny-patch4-window7-224"""							)
           if is_vision_available()
           else None
       )






   @slow
   def       A__    (    self:     Optional[int]							)	->      Dict:
       UpperCAmelCase_     :       int  		=					TFSwinForImageClassification.from_pretrained("""microsoft/swin-tiny-patch4-window7-224"""							)
       UpperCAmelCase_     :       Any  		=					self.default_image_processor

       UpperCAmelCase_     :       str  		=					Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
       UpperCAmelCase_     :       List[str]  		=					image_processor(images=__snake_case  ,return_tensors="""tf"""							)

       # forward pass
       UpperCAmelCase_     :       str  		=					model(__snake_case							)

       # verify the logits
       UpperCAmelCase_     :       Optional[int]  		=					tf.TensorShape((1, 1000)							)
       self.assertEqual(outputs.logits.shape  ,__snake_case							)
       UpperCAmelCase_     :       Dict  		=					tf.constant([-0.0_9_4_8, -0.6_4_5_4, -0.0_9_2_1]							)
       self.assertTrue(np.allclose(outputs.logits[0, :3]  ,__snake_case  ,atol=1e-4							)							)




import unittest

import numpy as np

from transformers import ElectraConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
       from transformers.models.electra.modeling_flax_electra import (
           FlaxElectraForCausalLM,
           FlaxElectraForMaskedLM,
           FlaxElectraForMultipleChoice,
           FlaxElectraForPreTraining,
           FlaxElectraForQuestionAnswering,
           FlaxElectraForSequenceClassification,
           FlaxElectraForTokenClassification,
           FlaxElectraModel,
       )





class 			lowerCAmelCase__(     unittest.TestCase    ):






    '''simple docstring'''





    def __init__(						self					: Any							, __snake_case					: Tuple							, __snake_case					: Union[str, Any]=13							, __snake_case					: Tuple=7							, __snake_case					: str=True							, __snake_case					: List[Any]=True							, __snake_case					: Optional[int]=True							, __snake_case					: List[str]=True							, __snake_case					: Tuple=99							, __snake_case					: int=24							, __snake_case					: int=32							, __snake_case					: Tuple=5							, __snake_case					: int=4							, __snake_case					: Any=37							, __snake_case					: int="gelu"							, __snake_case					: Union[str, Any]=0.1							, __snake_case					: Optional[Any]=0.1							, __snake_case					: str=512							, __snake_case					: List[Any]=16							, __snake_case					: Tuple=2							, __snake_case					: List[str]=0.02							, __snake_case					: Any=4							, ):





       '''simple docstring'''
       UpperCAmelCase_				:   Union[str, Any]							= parent
       UpperCAmelCase_				:   Dict							= batch_size
       UpperCAmelCase_				:   Union[str, Any]							= seq_length
       UpperCAmelCase_				:   Any							= is_training
       UpperCAmelCase_				:   Tuple							= use_attention_mask
       UpperCAmelCase_				:   Dict							= use_token_type_ids
       UpperCAmelCase_				:   str							= use_labels
       UpperCAmelCase_				:   Union[str, Any]							= vocab_size
       UpperCAmelCase_				:   Union[str, Any]							= hidden_size
       UpperCAmelCase_				:   Union[str, Any]							= embedding_size
       UpperCAmelCase_				:   Optional[int]							= num_hidden_layers
       UpperCAmelCase_				:   Tuple							= num_attention_heads
       UpperCAmelCase_				:   List[Any]							= intermediate_size
       UpperCAmelCase_				:   Union[str, Any]							= hidden_act
       UpperCAmelCase_				:   Any							= hidden_dropout_prob
       UpperCAmelCase_				:   List[str]							= attention_probs_dropout_prob
       UpperCAmelCase_				:   List[str]							= max_position_embeddings
       UpperCAmelCase_				:   Dict							= type_vocab_size
       UpperCAmelCase_				:   Tuple							= type_sequence_label_size
       UpperCAmelCase_				:   Dict							= initializer_range
       UpperCAmelCase_				:   Any							= num_choices





    def        _lowerCamelCase			(						self					: Optional[int]						):





       '''simple docstring'''
       UpperCAmelCase_				:   Any							= ids_tensor([self.batch_size, self.seq_length]							, self.vocab_size						)

       UpperCAmelCase_				:   Any							= None
       if self.use_attention_mask:
          UpperCAmelCase_				:   List[str]							= random_attention_mask([self.batch_size, self.seq_length]						)

       UpperCAmelCase_				:   List[str]							= None
       if self.use_token_type_ids:
          UpperCAmelCase_				:   str							= ids_tensor([self.batch_size, self.seq_length]							, self.type_vocab_size						)

       UpperCAmelCase_				:   int							= ElectraConfig(
           vocab_size=self.vocab_size							, hidden_size=self.hidden_size							, embedding_size=self.embedding_size							, num_hidden_layers=self.num_hidden_layers							, num_attention_heads=self.num_attention_heads							, 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							, max_position_embeddings=self.max_position_embeddings							, type_vocab_size=self.type_vocab_size							, initializer_range=self.initializer_range							, )

       return config, input_ids, token_type_ids, attention_mask





    def        _lowerCamelCase			(						self					: int						):





       '''simple docstring'''
       UpperCAmelCase_				:   List[str]							= self.prepare_config_and_inputs()
       UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_				:   Union[str, Any]							= config_and_inputs
       UpperCAmelCase_				:   Optional[Any]							= {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
       return config, inputs_dict





@require_flax
class 			lowerCAmelCase__(     snake_case__     ,     unittest.TestCase    ):






    '''simple docstring'''





    A_	:  Any								=			True

    A_	:  int								=			(
        (
            FlaxElectraModel,
            FlaxElectraForCausalLM,
            FlaxElectraForMaskedLM,
            FlaxElectraForPreTraining,
            FlaxElectraForTokenClassification,
            FlaxElectraForQuestionAnswering,
            FlaxElectraForMultipleChoice,
            FlaxElectraForSequenceClassification,
        )
        if is_flax_available()
        else ()
    )





    def        _lowerCamelCase			(						self					: Optional[int]						):





       '''simple docstring'''
       UpperCAmelCase_				:   List[str]							= FlaxElectraModelTester(self						)





    @slow
    def        _lowerCamelCase			(						self					: Union[str, Any]						):





       '''simple docstring'''
       for model_class_name in self.all_model_classes:
          if model_class_name == FlaxElectraForMaskedLM:
             UpperCAmelCase_				:   List[str]							= model_class_name.from_pretrained('''google/electra-small-generator'''						)
          else:
             UpperCAmelCase_				:   Optional[Any]							= model_class_name.from_pretrained('''google/electra-small-discriminator'''						)
          UpperCAmelCase_				:   Tuple							= model(np.ones((1, 1)						)						)
          self.assertIsNotNone(__snake_case						)