




"""simple docstring"""

def 				a (						__snake_case     :				float,    __snake_case     :				float  ):



				'''simple docstring'''





				return a + b


if __name__ == "__main__":
				__lowerCamelCase								=						5
				__lowerCamelCase								=						6
				print(f'''The sum of {a} + {b} is {add(a, b)}''')








"""simple docstring"""

import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    MODEL_FOR_PRETRAINING_MAPPING,
						    ElectraForCausalLM,
						    ElectraForMaskedLM,
						    ElectraForMultipleChoice,
						    ElectraForPreTraining,
						    ElectraForQuestionAnswering,
						    ElectraForSequenceClassification,
						    ElectraForTokenClassification,
						    ElectraModel,
						)
						from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST



class  _snake_case				:

				'''simple docstring'''




				def __init__(							self      :  List[str]					,							snake_case      :  Dict					,							snake_case      :  Optional[Any]=13					,							snake_case      :  Dict=7					,							snake_case      :  int=True					,							snake_case      :  Union[str, Any]=True					,							snake_case      :  Dict=True					,							snake_case      :  str=True					,							snake_case      :  Any=99					,							snake_case      :  Any=32					,							snake_case      :  Any=5					,							snake_case      :  List[Any]=4					,							snake_case      :  Tuple=37					,							snake_case      :  Optional[Any]="gelu"					,							snake_case      :  int=0.1					,							snake_case      :  Dict=0.1					,							snake_case      :  Tuple=512					,							snake_case      :  int=16					,							snake_case      :  str=2					,							snake_case      :  Optional[Any]=0.02					,							snake_case      :  List[Any]=3					,							snake_case      :  Dict=4					,							snake_case      :  Union[str, Any]=None					,							):
								UpperCAmelCase_					:List[Any]      			=      parent
								UpperCAmelCase_					:Any      			=      batch_size
								UpperCAmelCase_					:List[str]      			=      seq_length
								UpperCAmelCase_					:Optional[Any]      			=      is_training
								UpperCAmelCase_					:Tuple      			=      use_input_mask
								UpperCAmelCase_					:Any      			=      use_token_type_ids
								UpperCAmelCase_					:Dict      			=      use_labels
								UpperCAmelCase_					:Tuple      			=      vocab_size
								UpperCAmelCase_					:Optional[Any]      			=      hidden_size
								UpperCAmelCase_					:Optional[int]      			=      num_hidden_layers
								UpperCAmelCase_					:str      			=      num_attention_heads
								UpperCAmelCase_					:List[str]      			=      intermediate_size
								UpperCAmelCase_					:Any      			=      hidden_act
								UpperCAmelCase_					:Dict      			=      hidden_dropout_prob
								UpperCAmelCase_					:Optional[int]      			=      attention_probs_dropout_prob
								UpperCAmelCase_					:Dict      			=      max_position_embeddings
								UpperCAmelCase_					:Dict      			=      type_vocab_size
								UpperCAmelCase_					:Any      			=      type_sequence_label_size
								UpperCAmelCase_					:Optional[Any]      			=      initializer_range
								UpperCAmelCase_					:str      			=      num_labels
								UpperCAmelCase_					:Any      			=      num_choices
								UpperCAmelCase_					:str      			=      scope





				def 				snake_case_ (							self      :  Tuple     ):
								UpperCAmelCase_					:str      			=      ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size     )

								UpperCAmelCase_					:Optional[int]      			=      None
								if self.use_input_mask:
												UpperCAmelCase_					:Any      			=      random_attention_mask([self.batch_size, self.seq_length]     )

								UpperCAmelCase_					:Optional[Any]      			=      None
								if self.use_token_type_ids:
												UpperCAmelCase_					:Dict      			=      ids_tensor([self.batch_size, self.seq_length]					,							self.type_vocab_size     )

								UpperCAmelCase_					:str      			=      None
								UpperCAmelCase_					:Dict      			=      None
								UpperCAmelCase_					:str      			=      None
								if self.use_labels:
												UpperCAmelCase_					:str      			=      ids_tensor([self.batch_size]					,							self.type_sequence_label_size     )
												UpperCAmelCase_					:List[Any]      			=      ids_tensor([self.batch_size, self.seq_length]					,							self.num_labels     )
												UpperCAmelCase_					:Tuple      			=      ids_tensor([self.batch_size]					,							self.num_choices     )
												UpperCAmelCase_					:Dict      			=      ids_tensor([self.batch_size, self.seq_length]					,							1     )

								UpperCAmelCase_					:Dict      			=      self.get_config()

								return (
								    config,
								    input_ids,
								    token_type_ids,
								    input_mask,
								    sequence_labels,
								    token_labels,
								    choice_labels,
								    fake_token_labels,
								)





				def 				snake_case_ (							self      :  str     ):
								return ElectraConfig(
								    vocab_size=self.vocab_size					,							hidden_size=self.hidden_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					,							is_decoder=snake_case					,							initializer_range=self.initializer_range					,							)





				def 				snake_case_ (							self      :  List[Any]     ):
								(
								    (
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,
								)					:str      			=      self.prepare_config_and_inputs()

								UpperCAmelCase_					:Union[str, Any]      			=      True
								UpperCAmelCase_					:Any      			=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
								UpperCAmelCase_					:str      			=      ids_tensor([self.batch_size, self.seq_length]					,							vocab_size=2     )

								return (
								    config,
								    input_ids,
								    token_type_ids,
								    input_mask,
								    sequence_labels,
								    token_labels,
								    choice_labels,
								    encoder_hidden_states,
								    encoder_attention_mask,
								)





				def 				snake_case_ (							self      :  Union[str, Any]					,							snake_case      :  Tuple					,							snake_case      :  Tuple					,							snake_case      :  List[str]					,							snake_case      :  int					,							snake_case      :  str					,							snake_case      :  Dict					,							snake_case      :  Any					,							snake_case      :  Union[str, Any]					,							):
								UpperCAmelCase_					:str      			=      ElectraModel(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Dict      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case     )
								UpperCAmelCase_					:Tuple      			=      model(snake_case					,							token_type_ids=snake_case     )
								UpperCAmelCase_					:List[str]      			=      model(snake_case     )
								self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)     )





				def 				snake_case_ (							self      :  int					,							snake_case      :  Any					,							snake_case      :  Optional[Any]					,							snake_case      :  List[Any]					,							snake_case      :  Union[str, Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  List[Any]					,							snake_case      :  str					,							snake_case      :  Any					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      True
								UpperCAmelCase_					:Optional[int]      			=      ElectraModel(snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:int      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							encoder_hidden_states=snake_case					,							encoder_attention_mask=snake_case					,							)
								UpperCAmelCase_					:int      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							encoder_hidden_states=snake_case					,							)
								UpperCAmelCase_					:List[str]      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case     )
								self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)     )





				def 				snake_case_ (							self      :  str					,							snake_case      :  Any					,							snake_case      :  Dict					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[int]					,							snake_case      :  int					,							snake_case      :  List[str]					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							):
								UpperCAmelCase_					:Tuple      			=      ElectraForMaskedLM(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:str      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.vocab_size)     )





				def 				snake_case_ (							self      :  List[str]					,							snake_case      :  Dict					,							snake_case      :  Union[str, Any]					,							snake_case      :  Union[str, Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  List[str]					,							snake_case      :  Optional[int]					,							snake_case      :  Union[str, Any]					,							snake_case      :  int					,							snake_case      :  Tuple					,							):
								UpperCAmelCase_					:str      			=      ElectraForCausalLM(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Optional[Any]      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.vocab_size)     )





				def 				snake_case_ (							self      :  int					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							snake_case      :  Dict					,							snake_case      :  Optional[Any]					,							snake_case      :  Union[str, Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      self.num_labels
								UpperCAmelCase_					:Optional[int]      			=      ElectraForTokenClassification(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:List[str]      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.num_labels)     )





				def 				snake_case_ (							self      :  Tuple					,							snake_case      :  Tuple					,							snake_case      :  int					,							snake_case      :  int					,							snake_case      :  Optional[Any]					,							snake_case      :  Optional[int]					,							snake_case      :  Union[str, Any]					,							snake_case      :  List[str]					,							snake_case      :  List[Any]					,							):
								UpperCAmelCase_					:List[str]      			=      self.num_labels
								UpperCAmelCase_					:Union[str, Any]      			=      ElectraForPreTraining(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:int      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length)     )





				def 				snake_case_ (							self      :  Dict					,							snake_case      :  Any					,							snake_case      :  List[Any]					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[Any]					,							snake_case      :  Optional[int]					,							snake_case      :  Dict					,							snake_case      :  int					,							snake_case      :  int					,							):
								UpperCAmelCase_					:Optional[Any]      			=      self.num_labels
								UpperCAmelCase_					:Optional[int]      			=      ElectraForSequenceClassification(snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Any      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.num_labels)     )





				def 				snake_case_ (							self      :  Optional[int]					,							snake_case      :  Union[str, Any]					,							snake_case      :  List[str]					,							snake_case      :  Optional[int]					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							snake_case      :  str					,							snake_case      :  str					,							snake_case      :  List[Any]					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      ElectraForQuestionAnswering(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Optional[Any]      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							start_positions=snake_case					,							end_positions=snake_case					,							)
								self.parent.assertEqual(result.start_logits.shape					,							(self.batch_size, self.seq_length)     )
								self.parent.assertEqual(result.end_logits.shape					,							(self.batch_size, self.seq_length)     )





				def 				snake_case_ (							self      :  Union[str, Any]					,							snake_case      :  Optional[int]					,							snake_case      :  List[str]					,							snake_case      :  str					,							snake_case      :  Any					,							snake_case      :  str					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[int]					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      self.num_choices
								UpperCAmelCase_					:Dict      			=      ElectraForMultipleChoice(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:List[Any]      			=      input_ids.unsqueeze(1     ).expand(-1					,							self.num_choices					,							-1     ).contiguous()
								UpperCAmelCase_					:Dict      			=      token_type_ids.unsqueeze(1     ).expand(-1					,							self.num_choices					,							-1     ).contiguous()
								UpperCAmelCase_					:int      			=      input_mask.unsqueeze(1     ).expand(-1					,							self.num_choices					,							-1     ).contiguous()
								UpperCAmelCase_					:Optional[int]      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case					,							)
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.num_choices)     )





				def 				snake_case_ (							self      :  Any     ):
								UpperCAmelCase_					:List[Any]      			=      self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,
								)					:List[str]      			=      config_and_inputs
								UpperCAmelCase_					:Dict      			=      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict



@require_torch
class  _snake_case				(							A__							,						A__							,						unittest.TestCase       ):

				'''simple docstring'''




				UpperCamelCase__		     =(
				    (
				        ElectraModel,
				        ElectraForPreTraining,
				        ElectraForMaskedLM,
				        ElectraForCausalLM,
				        ElectraForMultipleChoice,
				        ElectraForTokenClassification,
				        ElectraForSequenceClassification,
				        ElectraForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCamelCase__		     =(
				    {
				        """feature-extraction""": ElectraModel,
				        """fill-mask""": ElectraForMaskedLM,
				        """question-answering""": ElectraForQuestionAnswering,
				        """text-classification""": ElectraForSequenceClassification,
				        """text-generation""": ElectraForCausalLM,
				        """token-classification""": ElectraForTokenClassification,
				        """zero-shot""": ElectraForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				UpperCamelCase__		     =True





				def 				snake_case_ (							self      :  List[str]					,							snake_case      :  List[str]					,							snake_case      :  Tuple					,							snake_case      :  List[Any]=False     ):
								UpperCAmelCase_					:Optional[int]      			=      super()._prepare_for_class(snake_case					,							snake_case					,							return_labels=snake_case     )

								if return_labels:
												if model_class in get_values(snake_case     ):
																UpperCAmelCase_					:Dict      			=      torch.zeros(
																    (self.model_tester.batch_size, self.model_tester.seq_length)					,							dtype=torch.long					,							device=snake_case     )
								return inputs_dict





				def 				snake_case_ (							self      :  Optional[int]     ):
								UpperCAmelCase_					:int      			=      ElectraModelTester(self     )
								UpperCAmelCase_					:List[str]      			=      ConfigTester(self					,							config_class=snake_case					,							hidden_size=37     )





				def 				snake_case_ (							self      :  List[Any]     ):
								self.config_tester.run_common_tests()





				def 				snake_case_ (							self      :  List[Any]     ):
								UpperCAmelCase_					:Union[str, Any]      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_model(*snake_case     )





				def 				snake_case_ (							self      :  List[str]     ):
								UpperCAmelCase_					:str      			=      self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_electra_model_as_decoder(*snake_case     )





				def 				snake_case_ (							self      :  Union[str, Any]     ):
								UpperCAmelCase_					:Dict      			=      self.model_tester.prepare_config_and_inputs()
								for type in ["absolute", "relative_key", "relative_key_query"]:
												UpperCAmelCase_					:Dict      			=      type
												self.model_tester.create_and_check_electra_model(*snake_case     )





				def 				snake_case_ (							self      :  str     ):
								UpperCAmelCase_					:Dict      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_masked_lm(*snake_case     )





				def 				snake_case_ (							self      :  Tuple     ):
								UpperCAmelCase_					:Dict      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_token_classification(*snake_case     )





				def 				snake_case_ (							self      :  Optional[int]     ):
								UpperCAmelCase_					:Optional[int]      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_pretraining(*snake_case     )





				def 				snake_case_ (							self      :  Dict     ):
								UpperCAmelCase_					:Any      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_sequence_classification(*snake_case     )





				def 				snake_case_ (							self      :  List[Any]     ):
								UpperCAmelCase_					:Union[str, Any]      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_question_answering(*snake_case     )





				def 				snake_case_ (							self      :  Any     ):
								UpperCAmelCase_					:int      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_multiple_choice(*snake_case     )





				@slow
				def 				snake_case_ (							self      :  Dict     ):
								for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCAmelCase_					:Optional[int]      			=      ElectraModel.from_pretrained(snake_case     )
												self.assertIsNotNone(snake_case     )





				def 				snake_case_ (							self      :  Any     ):
								UpperCAmelCase_					:Any      			=      self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_electra_for_causal_lm(*snake_case     )



@require_torch
class  _snake_case				(							unittest.TestCase       ):

				'''simple docstring'''




				@slow
				def 				snake_case_ (							self      :  List[Any]     ):
								UpperCAmelCase_					:Optional[int]      			=      ElectraModel.from_pretrained('''google/electra-small-discriminator'''     )
								UpperCAmelCase_					:Dict      			=      torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]     )
								UpperCAmelCase_					:int      			=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
								UpperCAmelCase_					:Optional[int]      			=      model(snake_case					,							attention_mask=snake_case     )[0]
								UpperCAmelCase_					:Optional[Any]      			=      torch.Size((1, 11, 256)     )
								self.assertEqual(output.shape					,							snake_case     )
								UpperCAmelCase_					:Optional[int]      			=      torch.tensor(
								    [[[0.4_471, 0.6_821, -0.3_265], [0.4_627, 0.5_255, -0.3_668], [0.4_532, 0.3_313, -0.4_344]]]     )

								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]					,							snake_case					,							atol=1e-4     )     )


