

"""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 		a_	:



      """simple docstring"""







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

           SCREAMING_SNAKE_CASE										=None
           if self.use_input_mask:
                SCREAMING_SNAKE_CASE										=random_attention_mask([self.batch_size, self.seq_length]    )

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

           SCREAMING_SNAKE_CASE										=None
           SCREAMING_SNAKE_CASE										=None
           SCREAMING_SNAKE_CASE										=None
           if self.use_labels:
                SCREAMING_SNAKE_CASE										=ids_tensor([self.batch_size]      ,self.type_sequence_label_size    )
                SCREAMING_SNAKE_CASE										=ids_tensor([self.batch_size, self.seq_length]      ,self.num_labels    )
                SCREAMING_SNAKE_CASE										=ids_tensor([self.batch_size]      ,self.num_choices    )
                SCREAMING_SNAKE_CASE										=ids_tensor([self.batch_size, self.seq_length]      ,1    )

           SCREAMING_SNAKE_CASE										=self.get_config()

           return (
               config,
               input_ids,
               token_type_ids,
               input_mask,
               sequence_labels,
               token_labels,
               choice_labels,
               fake_token_labels,
           )
      def 	_lowerCAmelCase					(				self					:							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=snake_case_      ,initializer_range=self.initializer_range      ,)
      def 	_lowerCAmelCase					(				self					:							Dict    ):
           (
               SCREAMING_SNAKE_CASE   
           )										=self.prepare_config_and_inputs()

           SCREAMING_SNAKE_CASE										=True
           SCREAMING_SNAKE_CASE										=floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
           SCREAMING_SNAKE_CASE										=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					:							Any      ,snake_case					:							Optional[Any]      ,snake_case					:							List[str]      ,snake_case					:							int      ,snake_case					:							Union[str, Any]      ,snake_case					:							int      ,snake_case					:							Union[str, Any]      ,snake_case					:							Optional[int]      ,snake_case					:							str      ,):
           SCREAMING_SNAKE_CASE										=ElectraModel(config=snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=model(snake_case_      ,attention_mask=snake_case_      ,token_type_ids=snake_case_    )
           SCREAMING_SNAKE_CASE										=model(snake_case_      ,token_type_ids=snake_case_    )
           SCREAMING_SNAKE_CASE										=model(snake_case_    )
           self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.hidden_size)    )
      def 	_lowerCAmelCase					(				self					:							Optional[Any]      ,snake_case					:							str      ,snake_case					:							str      ,snake_case					:							List[Any]      ,snake_case					:							str      ,snake_case					:							Union[str, Any]      ,snake_case					:							List[str]      ,snake_case					:							Any      ,snake_case					:							Any      ,snake_case					:							Any      ,):
           SCREAMING_SNAKE_CASE										=True
           SCREAMING_SNAKE_CASE										=ElectraModel(snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=model(
               snake_case_      ,attention_mask=snake_case_      ,token_type_ids=snake_case_      ,encoder_hidden_states=snake_case_      ,encoder_attention_mask=snake_case_      ,)
           SCREAMING_SNAKE_CASE										=model(
               snake_case_      ,attention_mask=snake_case_      ,token_type_ids=snake_case_      ,encoder_hidden_states=snake_case_      ,)
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							List[str]      ,snake_case					:							Any      ,snake_case					:							Optional[int]      ,snake_case					:							List[Any]      ,snake_case					:							Any      ,snake_case					:							str      ,snake_case					:							Tuple      ,snake_case					:							Optional[int]      ,snake_case					:							str      ,):
           SCREAMING_SNAKE_CASE										=ElectraForMaskedLM(config=snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							int      ,snake_case					:							Tuple      ,snake_case					:							List[str]      ,snake_case					:							str      ,snake_case					:							int      ,snake_case					:							Union[str, Any]      ,snake_case					:							int      ,snake_case					:							Tuple      ,snake_case					:							Any      ,snake_case					:							Dict      ,):
           SCREAMING_SNAKE_CASE										=ElectraForCausalLM(config=snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							Optional[Any]      ,snake_case					:							Dict      ,snake_case					:							Optional[Any]      ,snake_case					:							str      ,snake_case					:							Any      ,snake_case					:							Dict      ,snake_case					:							Any      ,snake_case					:							Dict      ,snake_case					:							Any      ,):
           SCREAMING_SNAKE_CASE										=self.num_labels
           SCREAMING_SNAKE_CASE										=ElectraForTokenClassification(config=snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							List[str]      ,snake_case					:							Optional[int]      ,snake_case					:							Optional[Any]      ,snake_case					:							Dict      ,snake_case					:							Any      ,snake_case					:							List[Any]      ,snake_case					:							List[Any]      ,snake_case					:							Any      ,snake_case					:							Optional[int]      ,):
           SCREAMING_SNAKE_CASE										=self.num_labels
           SCREAMING_SNAKE_CASE										=ElectraForPreTraining(config=snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							Union[str, Any]      ,snake_case					:							Tuple      ,snake_case					:							Optional[int]      ,snake_case					:							Any      ,snake_case					:							Optional[Any]      ,snake_case					:							Tuple      ,snake_case					:							str      ,snake_case					:							Tuple      ,snake_case					:							Dict      ,):
           SCREAMING_SNAKE_CASE										=self.num_labels
           SCREAMING_SNAKE_CASE										=ElectraForSequenceClassification(snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							Optional[Any]      ,snake_case					:							List[Any]      ,snake_case					:							Optional[Any]      ,snake_case					:							int      ,snake_case					:							List[str]      ,snake_case					:							List[Any]      ,snake_case					:							str      ,snake_case					:							Optional[Any]      ,snake_case					:							Union[str, Any]      ,):
           SCREAMING_SNAKE_CASE										=ElectraForQuestionAnswering(config=snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							Tuple      ,snake_case					:							Union[str, Any]      ,snake_case					:							Optional[Any]      ,snake_case					:							str      ,snake_case					:							Tuple      ,snake_case					:							List[str]      ,snake_case					:							Dict      ,snake_case					:							Any      ,snake_case					:							Optional[Any]      ,):
           SCREAMING_SNAKE_CASE										=self.num_choices
           SCREAMING_SNAKE_CASE										=ElectraForMultipleChoice(config=snake_case_    )
           model.to(snake_case_    )
           model.eval()
           SCREAMING_SNAKE_CASE										=input_ids.unsqueeze(1    ).expand(-1      ,self.num_choices      ,-1    ).contiguous()
           SCREAMING_SNAKE_CASE										=token_type_ids.unsqueeze(1    ).expand(-1      ,self.num_choices      ,-1    ).contiguous()
           SCREAMING_SNAKE_CASE										=input_mask.unsqueeze(1    ).expand(-1      ,self.num_choices      ,-1    ).contiguous()
           SCREAMING_SNAKE_CASE										=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 	_lowerCAmelCase					(				self					:							List[str]    ):
           SCREAMING_SNAKE_CASE										=self.prepare_config_and_inputs()
           (
               SCREAMING_SNAKE_CASE   
           )										=config_and_inputs
           SCREAMING_SNAKE_CASE										={"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
           return config, inputs_dict







@require_torch
class 		a_	(							_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 	_lowerCAmelCase					(				self					:							List[str]      ,snake_case					:							Tuple      ,snake_case					:							Optional[int]      ,snake_case					:							Dict=False    ):
           SCREAMING_SNAKE_CASE										=super()._prepare_for_class(snake_case_      ,snake_case_      ,return_labels=snake_case_    )

           if return_labels:
                if model_class in get_values(snake_case_    ):
                     SCREAMING_SNAKE_CASE										=torch.zeros(
                         (self.model_tester.batch_size, self.model_tester.seq_length)      ,dtype=torch.long      ,device=snake_case_    )
           return inputs_dict
      def 	_lowerCAmelCase					(				self					:							List[str]    ):
           SCREAMING_SNAKE_CASE										=ElectraModelTester(self    )
           SCREAMING_SNAKE_CASE										=ConfigTester(self      ,config_class=snake_case_      ,hidden_size=37    )
      def 	_lowerCAmelCase					(				self					:							List[Any]    ):
           self.config_tester.run_common_tests()
      def 	_lowerCAmelCase					(				self					:							List[str]    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_electra_model(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							List[str]    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs_for_decoder()
           self.model_tester.create_and_check_electra_model_as_decoder(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							Any    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
                SCREAMING_SNAKE_CASE										=type
                self.model_tester.create_and_check_electra_model(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							Dict    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_electra_for_masked_lm(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							Tuple    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_electra_for_token_classification(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							Tuple    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_electra_for_pretraining(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							Any    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_electra_for_sequence_classification(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							Tuple    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_electra_for_question_answering(*snake_case_    )
      def 	_lowerCAmelCase					(				self					:							Dict    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_electra_for_multiple_choice(*snake_case_    )
      @slow
      def 	_lowerCAmelCase					(				self					:							Any    ):
           for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                SCREAMING_SNAKE_CASE										=ElectraModel.from_pretrained(snake_case_    )
                self.assertIsNotNone(snake_case_    )


      def 	_lowerCAmelCase					(				self					:							Dict    ):
           SCREAMING_SNAKE_CASE										=self.model_tester.prepare_config_and_inputs_for_decoder()
           self.model_tester.create_and_check_electra_for_causal_lm(*snake_case_    )







@require_torch
class 		a_	(							unittest.TestCase					):



      """simple docstring"""







      @slow
      def 	_lowerCAmelCase					(				self					:							Tuple    ):
           SCREAMING_SNAKE_CASE										=ElectraModel.from_pretrained('google/electra-small-discriminator'    )
           SCREAMING_SNAKE_CASE										=torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]    )
           SCREAMING_SNAKE_CASE										=torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
           SCREAMING_SNAKE_CASE										=model(snake_case_      ,attention_mask=snake_case_    )[0]
           SCREAMING_SNAKE_CASE										=torch.Size((1, 11, 256)    )
           self.assertEqual(output.shape      ,snake_case_    )
           SCREAMING_SNAKE_CASE										=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    )    )




def       snake_case__    (       lowerCAmelCase_      ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE										=len(lowerCAmelCase_      )
     for _ in range(
         0,   int(((no_of_elements - 1) / 2) + 1      )      ):  # we don't need to traverse to end of list as
          for j in range(0,   no_of_elements - 1      ):
               if (
                   lst[j + 1] < lst[j]
               ):  # applying bubble sort algorithm from left to right (or forwards)
                    SCREAMING_SNAKE_CASE										=lst[j + 1]
                    SCREAMING_SNAKE_CASE										=lst[j]
                    SCREAMING_SNAKE_CASE										=temp
               if (
                   lst[no_of_elements - 1 - j] < lst[no_of_elements - 2 - j]
               ):  # applying bubble sort algorithm from right to left (or backwards)
                    SCREAMING_SNAKE_CASE										=lst[no_of_elements - 1 - j]
                    SCREAMING_SNAKE_CASE										=lst[no_of_elements - 2 - j]
                    SCREAMING_SNAKE_CASE										=temp
     return lst


if __name__ == "__main__":
 print("enter the list to be sorted")
 _lowerCamelCase								=[int(x) for x in input().split()]  # inputing elements of the list in one line
 _lowerCamelCase								=double_sort(lst)
 print("the sorted list is")
 print(sorted_lst)

