



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


						def __init__(			self    :	List[str]   ,							_a    :	Any   ,							_a    :	Union[str, Any]=1_3   ,							_a    :	Optional[Any]=7   ,							_a    :	List[str]=True   ,							_a    :	Optional[int]=True   ,							_a    :	List[str]=True   ,							_a    :	Dict=True   ,							_a    :	Tuple=9_9   ,							_a    :	Optional[Any]=3_2   ,							_a    :	List[Any]=5   ,							_a    :	str=4   ,							_a    :	Optional[int]=3_7   ,							_a    :	Any="gelu"   ,							_a    :	Optional[Any]=0.1   ,							_a    :	Union[str, Any]=0.1   ,							_a    :	Optional[Any]=5_1_2   ,							_a    :	Optional[int]=1_6   ,							_a    :	Optional[Any]=2   ,							_a    :	Dict=0.0_2   ,							_a    :	List[str]=3   ,							_a    :	Any=4   ,							_a    :	int=None   ,							):
													a__:							Any									=parent
													a__:							Any									=batch_size
													a__:							Optional[Any]									=seq_length
													a__:							Union[str, Any]									=is_training
													a__:							Optional[int]									=use_input_mask
													a__:							Optional[Any]									=use_token_type_ids
													a__:							Tuple									=use_labels
													a__:							Union[str, Any]									=vocab_size
													a__:							Optional[int]									=hidden_size
													a__:							Dict									=num_hidden_layers
													a__:							Optional[int]									=num_attention_heads
													a__:							List[Any]									=intermediate_size
													a__:							Any									=hidden_act
													a__:							Dict									=hidden_dropout_prob
													a__:							str									=attention_probs_dropout_prob
													a__:							int									=max_position_embeddings
													a__:							Optional[int]									=type_vocab_size
													a__:							Dict									=type_sequence_label_size
													a__:							Union[str, Any]									=initializer_range
													a__:							Tuple									=num_labels
													a__:							Any									=num_choices
													a__:							List[Any]									=scope


						def 	_lowerCamelCase      (			self    :	Dict      ):
													a__:							Tuple									=ids_tensor([self.batch_size, self.seq_length]   ,							self.vocab_size      )

													a__:							Any									=None
													if self.use_input_mask:
																				a__:							Tuple									=random_attention_mask([self.batch_size, self.seq_length]      )

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

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

													a__:							Any									=self.get_config()

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


						def 	_lowerCamelCase      (			self    :	Optional[int]      ):
													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=_A   ,							initializer_range=self.initializer_range   ,							)


						def 	_lowerCamelCase      (			self    :	Optional[Any]      ):
													(
													    a__							
													):							List[str]									=self.prepare_config_and_inputs()

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


						def 	_lowerCamelCase      (			self    :	int   ,							_a    :	Dict   ,							_a    :	List[Any]   ,							_a    :	Any   ,							_a    :	Dict   ,							_a    :	Optional[int]   ,							_a    :	List[str]   ,							_a    :	Union[str, Any]   ,							_a    :	Optional[int]   ,							_a    :	Tuple   ,							):
													a__:							Union[str, Any]									=True
													a__:							Optional[Any]									=ElectraModel(_A      )
													model.to(_A      )
													model.eval()
													a__:							int									=model(
													    _A   ,							attention_mask=_A   ,							token_type_ids=_A   ,							encoder_hidden_states=_A   ,							encoder_attention_mask=_A   ,							)
													a__:							Union[str, Any]									=model(
													    _A   ,							attention_mask=_A   ,							token_type_ids=_A   ,							encoder_hidden_states=_A   ,							)
													a__:							List[str]									=model(_A   ,							attention_mask=_A   ,							token_type_ids=_A      )
													self.parent.assertEqual(result.last_hidden_state.shape   ,							(self.batch_size, self.seq_length, self.hidden_size)      )


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


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


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


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


						def 	_lowerCamelCase      (			self    :	Optional[Any]   ,							_a    :	Union[str, Any]   ,							_a    :	Any   ,							_a    :	List[Any]   ,							_a    :	Dict   ,							_a    :	Union[str, Any]   ,							_a    :	Dict   ,							_a    :	List[str]   ,							_a    :	Optional[int]   ,							):
													a__:							int									=self.num_labels
													a__:							Tuple									=ElectraForSequenceClassification(_A      )
													model.to(_A      )
													model.eval()
													a__:							List[Any]									=model(_A   ,							attention_mask=_A   ,							token_type_ids=_A   ,							labels=_A      )
													self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.num_labels)      )


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







						def 	_lowerCamelCase      (			self    :	int      ):
													a__:							Dict									=self.prepare_config_and_inputs()
													(
													    a__							
													):							str									=config_and_inputs
													a__:							Union[str, Any]									={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
													return config, inputs_dict


@require_torch
class 						lowerCamelCase__			(		_a					,       _a					,       unittest.TestCase ):
						_lowerCAmelCase             =			(
						    (
						        ElectraModel,
						        ElectraForPreTraining,
						        ElectraForMaskedLM,
						        ElectraForCausalLM,
						        ElectraForMultipleChoice,
						        ElectraForTokenClassification,
						        ElectraForSequenceClassification,
						        ElectraForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						_lowerCAmelCase             =			(
						    {
						        """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 {}
						)
						_lowerCAmelCase             =			True


						def 	_lowerCamelCase      (			self    :	Union[str, Any]   ,							_a    :	List[str]   ,							_a    :	Union[str, Any]   ,							_a    :	List[str]=False      ):
													a__:							List[Any]									=super()._prepare_for_class(_A   ,							_A   ,							return_labels=_A      )

													if return_labels:
																				if model_class in get_values(_A      ):
																											a__:							List[Any]									=torch.zeros(
																											    (self.model_tester.batch_size, self.model_tester.seq_length)   ,							dtype=torch.long   ,							device=_A      )
													return inputs_dict


						def 	_lowerCamelCase      (			self    :	int      ):
													a__:							Optional[Any]									=ElectraModelTester(self      )
													a__:							Union[str, Any]									=ConfigTester(self   ,							config_class=_A   ,							hidden_size=3_7      )


						def 	_lowerCamelCase      (			self    :	Union[str, Any]      ):
													self.config_tester.run_common_tests()


						def 	_lowerCamelCase      (			self    :	Optional[Any]      ):
													a__:							Optional[Any]									=self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_model(*_A      )


						def 	_lowerCamelCase      (			self    :	Tuple      ):
													a__:							Tuple									=self.model_tester.prepare_config_and_inputs_for_decoder()
													self.model_tester.create_and_check_electra_model_as_decoder(*_A      )


						def 	_lowerCamelCase      (			self    :	int      ):
													a__:							Optional[Any]									=self.model_tester.prepare_config_and_inputs()
													for type in ["absolute", "relative_key", "relative_key_query"]:
																				a__:							Any									=type
																				self.model_tester.create_and_check_electra_model(*_A      )


						def 	_lowerCamelCase      (			self    :	List[Any]      ):
													a__:							Tuple									=self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_masked_lm(*_A      )


						def 	_lowerCamelCase      (			self    :	Dict      ):
													a__:							Any									=self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_token_classification(*_A      )


						def 	_lowerCamelCase      (			self    :	Tuple      ):
													a__:							Optional[Any]									=self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_pretraining(*_A      )


						def 	_lowerCamelCase      (			self    :	Tuple      ):
													a__:							int									=self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_sequence_classification(*_A      )


						def 	_lowerCamelCase      (			self    :	Any      ):
													a__:							Tuple									=self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_question_answering(*_A      )


						def 	_lowerCamelCase      (			self    :	str      ):
													a__:							Any									=self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_multiple_choice(*_A      )


						@slow
						def 	_lowerCamelCase      (			self    :	str      ):
													for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				a__:							Dict									=ElectraModel.from_pretrained(_A      )
																				self.assertIsNotNone(_A      )







						def 	_lowerCamelCase      (			self    :	List[Any]      ):
													a__:							Optional[Any]									=self.model_tester.prepare_config_and_inputs_for_decoder()
													self.model_tester.create_and_check_electra_for_causal_lm(*_A      )


@require_torch
class 						lowerCamelCase__			(		unittest.TestCase ):


						@slow
						def 	_lowerCamelCase      (			self    :	str      ):
													a__:							Any									=ElectraModel.from_pretrained("google/electra-small-discriminator"      )
													a__:							Any									=torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]      )
													a__:							Tuple									=torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
													a__:							Tuple									=model(_A   ,							attention_mask=_A      )[0]
													a__:							List[str]									=torch.Size((1, 1_1, 2_5_6)      )
													self.assertEqual(output.shape   ,							_A      )
													a__:							Optional[Any]									=torch.tensor(
													    [[[0.4_4_7_1, 0.6_8_2_1, -0.3_2_6_5], [0.4_6_2_7, 0.5_2_5_5, -0.3_6_6_8], [0.4_5_3_2, 0.3_3_1_3, -0.4_3_4_4]]]      )

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






"""simple docstring"""







import math
def     __UpperCAmelCase							(       UpperCAmelCase_       :							int    )				->     str:

	'''simple docstring'''





	if number == 0:
		__snake_case     :				Any 						=					'Zero'
		return words
	else:
		__snake_case     :				Optional[Any] 						=					math.logaa(UpperCAmelCase_    )
		__snake_case     :				Optional[Any] 						=					digits + 1
		__snake_case     :				List[str] 						=					{}
		__snake_case     :				List[str] 						=					''
		__snake_case     :				Any 						=					'One'
		__snake_case     :				List[str] 						=					'Two'
		__snake_case     :				Tuple 						=					'Three'
		__snake_case     :				str 						=					'Four'
		__snake_case     :				int 						=					'Five'
		__snake_case     :				Optional[Any] 						=					'Six'
		__snake_case     :				str 						=					'Seven'
		__snake_case     :				Optional[Any] 						=					'Eight'
		__snake_case     :				Tuple 						=					'Nine'

		__snake_case     :				Tuple 						=					{}
		__snake_case     :				Optional[int] 						=					''
		__snake_case     :				str 						=					'Twenty'
		__snake_case     :				List[str] 						=					'Thirty'
		__snake_case     :				str 						=					'Forty'
		__snake_case     :				Union[str, Any] 						=					'Fifty'
		__snake_case     :				str 						=					'Sixty'
		__snake_case     :				Tuple 						=					'Seventy'
		__snake_case     :				Dict 						=					'Eighty'
		__snake_case     :				Optional[Any] 						=					'Ninety'

		__snake_case     :				List[Any] 						=					{}
		__snake_case     :				Optional[Any] 						=					'Ten'
		__snake_case     :				List[str] 						=					'Eleven'
		__snake_case     :				Any 						=					'Twelve'
		__snake_case     :				Tuple 						=					'Thirteen'
		__snake_case     :				Tuple 						=					'Fourteen'
		__snake_case     :				Optional[int] 						=					'Fifteen'
		__snake_case     :				Any 						=					'Sixteen'
		__snake_case     :				int 						=					'Seventeen'
		__snake_case     :				Dict 						=					'Eighteen'
		__snake_case     :				List[Any] 						=					'Nineteen'

		__snake_case     :				List[Any] 						=					{}
		__snake_case     :				List[Any] 						=					'Hundred,'
		__snake_case     :				Union[str, Any] 						=					'Thousand,'
		__snake_case     :				List[Any] 						=					'Lakh,'
		__snake_case     :				List[Any] 						=					'Crore,'

		__snake_case     :				List[Any] 						=					number
		__snake_case     :				List[Any] 						=					''
		__snake_case     :				List[Any] 						=					0
		__snake_case     :				Union[str, Any] 						=					int(UpperCAmelCase_    )
		while counter < digits:
			__snake_case     :				List[str] 						=					temp_num % 10
			if counter % 2 == 0:
				__snake_case     :				Tuple 						=					''
				if counter in placevalue and current != 0:
					__snake_case     :				List[str] 						=					placevalue[counter]
				if counter == 2:
					__snake_case     :				Dict 						=					singles[current] + addition + words
				elif counter == 0:
					if ((temp_num % 1_00) // 10) == 1:
						__snake_case     :				Dict 						=					teens[current] + addition + words
						__snake_case     :				Dict 						=					temp_num // 10
						counter += 1
					else:
						__snake_case     :				Optional[Any] 						=					singles[current] + addition + words

				else:
					__snake_case     :				Any 						=					doubles[current] + addition + words

			else:
				if counter == 1:
					if current == 1:
						__snake_case     :				Dict 						=					teens[number % 10] + words
					else:
						__snake_case     :				Optional[int] 						=					''
						if counter in placevalue:
							__snake_case     :				Dict 						=					placevalue[counter]
						__snake_case     :				Union[str, Any] 						=					doubles[current] + addition + words
				else:
					__snake_case     :				List[Any] 						=					''
					if counter in placevalue:
						if current == 0 and ((temp_num % 1_00) // 10) == 0:
							__snake_case     :				Optional[Any] 						=					''
						else:
							__snake_case     :				Any 						=					placevalue[counter]
					if ((temp_num % 1_00) // 10) == 1:
						__snake_case     :				int 						=					teens[current] + addition + words
						__snake_case     :				Any 						=					temp_num // 10
						counter += 1
					else:
						__snake_case     :				List[str] 						=					singles[current] + addition + words
			counter += 1
			__snake_case     :				str 						=					temp_num // 10
	return words


if __name__ == "__main__":
	import doctest

	doctest.testmod()





