


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






				'''simple docstring'''



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


				def 		__magic_name__(	self      :List[str]     )		->      Tuple:
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		ids_tensor([self.batch_size, self.seq_length]      ,      self.vocab_size     )

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

										__SCREAMING_SNAKE_CASE						:					str		      =		None
										if self.use_token_type_ids:
																__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		ids_tensor([self.batch_size, self.seq_length]      ,      self.type_vocab_size     )

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

										__SCREAMING_SNAKE_CASE						:					Tuple		      =		self.get_config()

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


				def 		__magic_name__(	self      :Tuple     )		->      List[Any]:
										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=lowerCAmelCase__      ,      initializer_range=self.initializer_range      ,      )


				def 		__magic_name__(	self      :int     )		->      List[Any]:
										(
										    (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      
										)						:					Tuple		      =		self.prepare_config_and_inputs()

										__SCREAMING_SNAKE_CASE						:					int		      =		True
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
										__SCREAMING_SNAKE_CASE						:					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 		__magic_name__(	self      :str      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :Dict      ,      )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					Dict		      =		ElectraModel(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__     )
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		model(lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__     )
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		model(lowerCAmelCase__     )
										self.parent.assertEqual(result.last_hidden_state.shape      ,      (self.batch_size, self.seq_length, self.hidden_size)     )


				def 		__magic_name__(	self      :Optional[Any]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :int      ,      )		->      Tuple:
										__SCREAMING_SNAKE_CASE						:					str		      =		True
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		ElectraModel(lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      encoder_hidden_states=lowerCAmelCase__      ,      encoder_attention_mask=lowerCAmelCase__      ,      )
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      encoder_hidden_states=lowerCAmelCase__      ,      )
										__SCREAMING_SNAKE_CASE						:					Dict		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__     )
										self.parent.assertEqual(result.last_hidden_state.shape      ,      (self.batch_size, self.seq_length, self.hidden_size)     )


				def 		__magic_name__(	self      :Optional[int]      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :List[str]      ,      )		->      Optional[int]:
										__SCREAMING_SNAKE_CASE						:					int		      =		ElectraForMaskedLM(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Any		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      labels=lowerCAmelCase__     )
										self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.seq_length, self.vocab_size)     )


				def 		__magic_name__(	self      :Union[str, Any]      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :List[Any]      ,      )		->      List[str]:
										__SCREAMING_SNAKE_CASE						:					int		      =		ElectraForCausalLM(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Dict		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      labels=lowerCAmelCase__     )
										self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.seq_length, self.vocab_size)     )


				def 		__magic_name__(	self      :Optional[Any]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Tuple      ,      )		->      int:
										__SCREAMING_SNAKE_CASE						:					int		      =		self.num_labels
										__SCREAMING_SNAKE_CASE						:					Any		      =		ElectraForTokenClassification(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      labels=lowerCAmelCase__     )
										self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.seq_length, self.num_labels)     )


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


				def 		__magic_name__(	self      :Union[str, Any]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :int      ,      )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					Any		      =		self.num_labels
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		ElectraForSequenceClassification(lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      labels=lowerCAmelCase__     )
										self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.num_labels)     )


				def 		__magic_name__(	self      :Optional[int]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Dict      ,      )		->      Optional[Any]:
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		ElectraForQuestionAnswering(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      start_positions=lowerCAmelCase__      ,      end_positions=lowerCAmelCase__      ,      )
										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 		__magic_name__(	self      :Union[str, Any]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Any      ,      )		->      Any:
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		self.num_choices
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		ElectraForMultipleChoice(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		input_ids.unsqueeze(1     ).expand(-1      ,      self.num_choices      ,      -1     ).contiguous()
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		token_type_ids.unsqueeze(1     ).expand(-1      ,      self.num_choices      ,      -1     ).contiguous()
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		input_mask.unsqueeze(1     ).expand(-1      ,      self.num_choices      ,      -1     ).contiguous()
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      labels=lowerCAmelCase__      ,      )
										self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.num_choices)     )



				def 		__magic_name__(	self      :int     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		self.prepare_config_and_inputs()
										(
										    (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      
										)						:					int		      =		config_and_inputs
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
										return config, inputs_dict




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






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__    :      List[Any]      =		(
				    (
				        ElectraModel,
				        ElectraForPreTraining,
				        ElectraForMaskedLM,
				        ElectraForCausalLM,
				        ElectraForMultipleChoice,
				        ElectraForTokenClassification,
				        ElectraForSequenceClassification,
				        ElectraForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE__    :      Any      =		(
				    {
				        '''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 {}
				)
				SCREAMING_SNAKE_CASE__    :      Any      =		True


				def 		__magic_name__(	self      :List[Any]      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :str=False     )		->      str:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		super()._prepare_for_class(lowerCAmelCase__      ,      lowerCAmelCase__      ,      return_labels=lowerCAmelCase__     )

										if return_labels:
																if model_class in get_values(lowerCAmelCase__     ):
																						__SCREAMING_SNAKE_CASE						:					str		      =		torch.zeros(
																						    (self.model_tester.batch_size, self.model_tester.seq_length)      ,      dtype=torch.long      ,      device=lowerCAmelCase__     )
										return inputs_dict


				def 		__magic_name__(	self      :List[Any]     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		ElectraModelTester(self     )
										__SCREAMING_SNAKE_CASE						:					int		      =		ConfigTester(self      ,      config_class=lowerCAmelCase__      ,      hidden_size=37     )


				def 		__magic_name__(	self      :Optional[int]     )		->      Optional[int]:
										self.config_tester.run_common_tests()


				def 		__magic_name__(	self      :List[str]     )		->      Optional[int]:
										__SCREAMING_SNAKE_CASE						:					int		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_electra_model(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :str     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					Dict		      =		self.model_tester.prepare_config_and_inputs_for_decoder()
										self.model_tester.create_and_check_electra_model_as_decoder(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :List[str]     )		->      str:
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
																__SCREAMING_SNAKE_CASE						:					Any		      =		type
																self.model_tester.create_and_check_electra_model(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :List[str]     )		->      List[str]:
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_electra_for_masked_lm(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :List[Any]     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_electra_for_token_classification(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Dict     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					Any		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_electra_for_pretraining(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :List[Any]     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_electra_for_sequence_classification(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :List[str]     )		->      Any:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_electra_for_question_answering(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Optional[int]     )		->      int:
										__SCREAMING_SNAKE_CASE						:					str		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_electra_for_multiple_choice(*lowerCAmelCase__     )


				@slow
				def 		__magic_name__(	self      :Union[str, Any]     )		->      Dict:
										for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__SCREAMING_SNAKE_CASE						:					Any		      =		ElectraModel.from_pretrained(lowerCAmelCase__     )
																self.assertIsNotNone(lowerCAmelCase__     )



				def 		__magic_name__(	self      :Optional[int]     )		->      int:
										__SCREAMING_SNAKE_CASE						:					Dict		      =		self.model_tester.prepare_config_and_inputs_for_decoder()
										self.model_tester.create_and_check_electra_for_causal_lm(*lowerCAmelCase__     )




@require_torch
class 	_lowercase				(      unittest.TestCase	):






				'''simple docstring'''



				@slow
				def 		__magic_name__(	self      :str     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		ElectraModel.from_pretrained('''google/electra-small-discriminator'''     )
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]     )
										__SCREAMING_SNAKE_CASE						:					Any		      =		torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__     )[0]
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		torch.Size((1, 11, 256)     )
										self.assertEqual(output.shape      ,      lowerCAmelCase__     )
										__SCREAMING_SNAKE_CASE						:					str		      =		torch.tensor(
										    [[[0.4471, 0.6821, -0.3265], [0.4627, 0.5255, -0.3668], [0.4532, 0.3313, -0.4344]]]     )

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




from .number_theory.prime_numbers import next_prime
class 	_lowercase				:






				'''simple docstring'''



				def __init__(	self      :Tuple      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :int | None = None      ,      lowerCAmelCase__      :float | None = None      ,      )		->      None:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		size_table
										__SCREAMING_SNAKE_CASE						:					Dict		      =		[None] * self.size_table
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		0.75 if lim_charge is None else lim_charge
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		1 if charge_factor is None else charge_factor
										__SCREAMING_SNAKE_CASE						:					list		      =		[]
										__SCREAMING_SNAKE_CASE						:					dict		      =		{}


				def 		__magic_name__(	self      :List[Any]     )		->      Tuple:
										return self._keys


				def 		__magic_name__(	self      :Any     )		->      Dict:
										return sum(1 for slot in self.values if slot is not None     ) / (
										    self.size_table * self.charge_factor
										)


				def 		__magic_name__(	self      :Optional[Any]      ,      lowerCAmelCase__      :Union[str, Any]     )		->      Optional[Any]:
										return key % self.size_table


				def 		__magic_name__(	self      :int      ,      lowerCAmelCase__      :Union[str, Any]     )		->      List[Any]:
										print(f'''step {step_ord}'''     )
										print(list(range(len(self.values     )     )     )     )
										print(self.values     )


				def 		__magic_name__(	self      :List[str]      ,      lowerCAmelCase__      :Optional[Any]     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		1
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		values
										for value in values:
																self.insert_data(lowerCAmelCase__     )
																self._step_by_step(lowerCAmelCase__     )
																i += 1


				def 		__magic_name__(	self      :Tuple      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Union[str, Any]     )		->      str:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		data
										__SCREAMING_SNAKE_CASE						:					Any		      =		data


				def 		__magic_name__(	self      :Optional[int]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :List[str]=None     )		->      int:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		self.hash_function(key + 1     )

										while self.values[new_key] is not None and self.values[new_key] != key:
																if self.values.count(lowerCAmelCase__     ) > 0:
																						__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		self.hash_function(new_key + 1     )
																else:
																						__SCREAMING_SNAKE_CASE						:					int		      =		None
																						break

										return new_key


				def 		__magic_name__(	self      :Optional[int]     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					str		      =		[value for value in self.values if value is not None]
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		next_prime(self.size_table      ,      factor=2     )
										self._keys.clear()
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		[None] * self.size_table  # hell's pointers D: don't DRY ;/
										for value in survivor_values:
																self.insert_data(lowerCAmelCase__     )



				def 		__magic_name__(	self      :Tuple      ,      lowerCAmelCase__      :str     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		self.hash_function(lowerCAmelCase__     )

										if self.values[key] is None:
																self._set_value(lowerCAmelCase__      ,      lowerCAmelCase__     )

										elif self.values[key] == data:
																pass

										else:
																__SCREAMING_SNAKE_CASE						:					Tuple		      =		self._collision_resolution(lowerCAmelCase__      ,      lowerCAmelCase__     )
																if collision_resolution is not None:
																						self._set_value(lowerCAmelCase__      ,      lowerCAmelCase__     )
																else:
																						self.rehashing()
																						self.insert_data(lowerCAmelCase__     )
