


from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import tensorflow as tf

							from transformers import (
							    TF_MODEL_FOR_PRETRAINING_MAPPING,
							    TFMobileBertForMaskedLM,
							    TFMobileBertForMultipleChoice,
							    TFMobileBertForNextSentencePrediction,
							    TFMobileBertForPreTraining,
							    TFMobileBertForQuestionAnswering,
							    TFMobileBertForSequenceClassification,
							    TFMobileBertForTokenClassification,
							    TFMobileBertModel,
							)







@require_tf
class 							UpperCamelCase__ (						SCREAMING_SNAKE_CASE__				,					SCREAMING_SNAKE_CASE__				,					unittest.TestCase ):
					__SCREAMING_SNAKE_CASE							:	Optional[Any]            = (
					    (
					        TFMobileBertModel,
					        TFMobileBertForMaskedLM,
					        TFMobileBertForNextSentencePrediction,
					        TFMobileBertForPreTraining,
					        TFMobileBertForQuestionAnswering,
					        TFMobileBertForSequenceClassification,
					        TFMobileBertForTokenClassification,
					        TFMobileBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else ()
					)
					__SCREAMING_SNAKE_CASE							:	Union[str, Any]            = (
					    {
					        '''feature-extraction''': TFMobileBertModel,
					        '''fill-mask''': TFMobileBertForMaskedLM,
					        '''question-answering''': TFMobileBertForQuestionAnswering,
					        '''text-classification''': TFMobileBertForSequenceClassification,
					        '''token-classification''': TFMobileBertForTokenClassification,
					        '''zero-shot''': TFMobileBertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					__SCREAMING_SNAKE_CASE							:	Union[str, Any]            = False
					__SCREAMING_SNAKE_CASE							:	str            = False

					def 	UpperCAmelCase__							(  self							: Optional[Any]				,       UpperCamelCase__							: Any				,       UpperCamelCase__							: Union[str, Any]				,       UpperCamelCase__							: Optional[int]=False							):






										'''simple docstring'''






										lowercase_					=      super()._prepare_for_class(__lowerCAmelCase				,       __lowerCAmelCase				,       return_labels=__lowerCAmelCase							)

										if return_labels:
															if model_class in get_values(__lowerCAmelCase							):
																				lowercase_					=      tf.zeros(self.model_tester.batch_size				,       dtype=tf.intaa							)

										return inputs_dict







					class 							UpperCamelCase__ (						SCREAMING_SNAKE_CASE__ ):

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






															'''simple docstring'''






															lowercase_					=      parent
															lowercase_					=      batch_size
															lowercase_					=      seq_length
															lowercase_					=      is_training
															lowercase_					=      use_input_mask
															lowercase_					=      use_token_type_ids
															lowercase_					=      use_labels
															lowercase_					=      vocab_size
															lowercase_					=      hidden_size
															lowercase_					=      num_hidden_layers
															lowercase_					=      num_attention_heads
															lowercase_					=      intermediate_size
															lowercase_					=      hidden_act
															lowercase_					=      hidden_dropout_prob
															lowercase_					=      attention_probs_dropout_prob
															lowercase_					=      max_position_embeddings
															lowercase_					=      type_vocab_size
															lowercase_					=      type_sequence_label_size
															lowercase_					=      initializer_range
															lowercase_					=      num_labels
															lowercase_					=      num_choices
															lowercase_					=      scope
															lowercase_					=      embedding_size

										def 	UpperCAmelCase__							(  self							: Optional[int]							):






															'''simple docstring'''






															lowercase_					=      ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size							)

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

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

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

															lowercase_					=      MobileBertConfig(
															    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				,       initializer_range=self.initializer_range				,       embedding_size=self.embedding_size				,       )

															return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

										def 	UpperCAmelCase__							(  self							: str				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: Tuple				,       UpperCamelCase__							: Optional[int]				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: Optional[int]				,       UpperCamelCase__							: Any				,       UpperCamelCase__							: Dict							):






															'''simple docstring'''






															lowercase_					=      TFMobileBertModel(config=__lowerCAmelCase							)
															lowercase_					=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
															lowercase_					=      model(__lowerCAmelCase							)

															lowercase_					=      [input_ids, input_mask]
															lowercase_					=      model(__lowerCAmelCase							)

															lowercase_					=      model(__lowerCAmelCase							)

															self.parent.assertEqual(
															    result.last_hidden_state.shape				,       (self.batch_size, self.seq_length, self.hidden_size)							)
															self.parent.assertEqual(result.pooler_output.shape				,       (self.batch_size, self.hidden_size)							)

										def 	UpperCAmelCase__							(  self							: List[str]				,       UpperCamelCase__							: List[str]				,       UpperCamelCase__							: List[str]				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: List[str]				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: Any				,       UpperCamelCase__							: Union[str, Any]							):






															'''simple docstring'''






															lowercase_					=      TFMobileBertForMaskedLM(config=__lowerCAmelCase							)
															lowercase_					=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
															lowercase_					=      model(__lowerCAmelCase							)
															self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.seq_length, self.vocab_size)							)

										def 	UpperCAmelCase__							(  self							: Any				,       UpperCamelCase__							: Optional[int]				,       UpperCamelCase__							: int				,       UpperCamelCase__							: Tuple				,       UpperCamelCase__							: Dict				,       UpperCamelCase__							: str				,       UpperCamelCase__							: Dict				,       UpperCamelCase__							: Tuple							):






															'''simple docstring'''






															lowercase_					=      TFMobileBertForNextSentencePrediction(config=__lowerCAmelCase							)
															lowercase_					=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
															lowercase_					=      model(__lowerCAmelCase							)
															self.parent.assertEqual(result.logits.shape				,       (self.batch_size, 2)							)

										def 	UpperCAmelCase__							(  self							: Union[str, Any]				,       UpperCamelCase__							: Optional[int]				,       UpperCamelCase__							: Optional[int]				,       UpperCamelCase__							: Any				,       UpperCamelCase__							: str				,       UpperCamelCase__							: List[str]				,       UpperCamelCase__							: Union[str, Any]				,       UpperCamelCase__							: Optional[int]							):






															'''simple docstring'''






															lowercase_					=      TFMobileBertForPreTraining(config=__lowerCAmelCase							)
															lowercase_					=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
															lowercase_					=      model(__lowerCAmelCase							)
															self.parent.assertEqual(
															    result.prediction_logits.shape				,       (self.batch_size, self.seq_length, self.vocab_size)							)
															self.parent.assertEqual(result.seq_relationship_logits.shape				,       (self.batch_size, 2)							)

										def 	UpperCAmelCase__							(  self							: Optional[Any]				,       UpperCamelCase__							: List[Any]				,       UpperCamelCase__							: List[str]				,       UpperCamelCase__							: str				,       UpperCamelCase__							: str				,       UpperCamelCase__							: List[Any]				,       UpperCamelCase__							: Tuple				,       UpperCamelCase__							: str							):






															'''simple docstring'''






															lowercase_					=      self.num_labels
															lowercase_					=      TFMobileBertForSequenceClassification(config=__lowerCAmelCase							)
															lowercase_					=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
															lowercase_					=      model(__lowerCAmelCase							)
															self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.num_labels)							)

										def 	UpperCAmelCase__							(  self							: Tuple				,       UpperCamelCase__							: str				,       UpperCamelCase__							: Dict				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: int				,       UpperCamelCase__							: int				,       UpperCamelCase__							: Union[str, Any]				,       UpperCamelCase__							: str							):






															'''simple docstring'''






															lowercase_					=      self.num_choices
															lowercase_					=      TFMobileBertForMultipleChoice(config=__lowerCAmelCase							)
															lowercase_					=      tf.tile(tf.expand_dims(__lowerCAmelCase				,       1							)				,       (1, self.num_choices, 1)							)
															lowercase_					=      tf.tile(tf.expand_dims(__lowerCAmelCase				,       1							)				,       (1, self.num_choices, 1)							)
															lowercase_					=      tf.tile(tf.expand_dims(__lowerCAmelCase				,       1							)				,       (1, self.num_choices, 1)							)
															lowercase_					=      {
															    """input_ids""": multiple_choice_inputs_ids,
															    """attention_mask""": multiple_choice_input_mask,
															    """token_type_ids""": multiple_choice_token_type_ids,
															}
															lowercase_					=      model(__lowerCAmelCase							)
															self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.num_choices)							)

										def 	UpperCAmelCase__							(  self							: List[str]				,       UpperCamelCase__							: Optional[int]				,       UpperCamelCase__							: int				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: List[Any]				,       UpperCamelCase__							: str				,       UpperCamelCase__							: Any				,       UpperCamelCase__							: Optional[Any]							):






															'''simple docstring'''






															lowercase_					=      self.num_labels
															lowercase_					=      TFMobileBertForTokenClassification(config=__lowerCAmelCase							)
															lowercase_					=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
															lowercase_					=      model(__lowerCAmelCase							)
															self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.seq_length, self.num_labels)							)

										def 	UpperCAmelCase__							(  self							: Optional[Any]				,       UpperCamelCase__							: Dict				,       UpperCamelCase__							: str				,       UpperCamelCase__							: Union[str, Any]				,       UpperCamelCase__							: str				,       UpperCamelCase__							: Union[str, Any]				,       UpperCamelCase__							: Optional[Any]				,       UpperCamelCase__							: List[str]							):






															'''simple docstring'''






															lowercase_					=      TFMobileBertForQuestionAnswering(config=__lowerCAmelCase							)
															lowercase_					=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
															lowercase_					=      model(__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 	UpperCAmelCase__							(  self							: Union[str, Any]							):






															'''simple docstring'''






															lowercase_					=      self.prepare_config_and_inputs()
															(
															    lowercase_      
															)					=      config_and_inputs
															lowercase_					=      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
															return config, inputs_dict



					def 	UpperCAmelCase__							(  self							: str							):






										'''simple docstring'''






										lowercase_					=      TFMobileBertModelTest.TFMobileBertModelTester(self							)
										lowercase_					=      ConfigTester(self				,       config_class=__lowerCAmelCase				,       hidden_size=37							)

					def 	UpperCAmelCase__							(  self							: str							):






										'''simple docstring'''






										self.config_tester.run_common_tests()

					def 	UpperCAmelCase__							(  self							: Optional[Any]							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_model(*__lowerCAmelCase							)

					def 	UpperCAmelCase__							(  self							: str							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_for_masked_lm(*__lowerCAmelCase							)

					def 	UpperCAmelCase__							(  self							: str							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__lowerCAmelCase							)

					def 	UpperCAmelCase__							(  self							: Dict							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__lowerCAmelCase							)

					def 	UpperCAmelCase__							(  self							: Union[str, Any]							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_for_pretraining(*__lowerCAmelCase							)

					def 	UpperCAmelCase__							(  self							: List[Any]							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_for_question_answering(*__lowerCAmelCase							)

					def 	UpperCAmelCase__							(  self							: int							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__lowerCAmelCase							)

					def 	UpperCAmelCase__							(  self							: Optional[int]							):






										'''simple docstring'''






										lowercase_					=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_mobilebert_for_token_classification(*__lowerCAmelCase							)







					@slow
					def 	UpperCAmelCase__							(  self							: Tuple							):






										'''simple docstring'''






										for model_name in ["google/mobilebert-uncased"]:
															lowercase_					=      TFMobileBertModel.from_pretrained(__lowerCAmelCase							)
															self.assertIsNotNone(__lowerCAmelCase							)







@require_tf
class 							UpperCamelCase__ (						unittest.TestCase ):

					@slow
					def 	UpperCAmelCase__							(  self							: List[str]							):






										'''simple docstring'''






										lowercase_					=      TFMobileBertForPreTraining.from_pretrained("""google/mobilebert-uncased"""							)
										lowercase_					=      tf.constant([[0, 1, 2, 3, 4, 5]]							)
										lowercase_					=      model(__lowerCAmelCase							)[0]

										lowercase_					=      [1, 6, 30_522]
										self.assertEqual(output.shape				,       __lowerCAmelCase							)

										lowercase_					=      tf.constant(
										    [
										        [
										            [-4.5_919_547, -9.248_295, -9.645_256],
										            [-6.7_306_175, -6.440_284, -6.6_052_837],
										            [-7.2_743_506, -6.7_847_915, -6.024_673],
										        ]
										    ]							)
										tf.debugging.assert_near(output[:, :3, :3]				,       __lowerCAmelCase				,       atol=1e-4							)










'''simple docstring'''

def 				snake_case       (  a_				:			list						)							->					list:





      """simple docstring"""

      UpperCamelCase_					: List[str]            =				False
      while is_sorted is False:  # Until all the indices are traversed keep looping
            UpperCamelCase_					: Tuple            =				True
            for i in range(0     , len(a_						) - 1     , 2						):  # iterating over all even indices
                  if input_list[i] > input_list[i + 1]:
                        UpperCamelCase_     ,      UpperCamelCase_					: Optional[Any]            =				input_list[i + 1], input_list[i]
                        # swapping if elements not in order
                        UpperCamelCase_					: Any            =				False

            for i in range(1     , len(a_						) - 1     , 2						):  # iterating over all odd indices
                  if input_list[i] > input_list[i + 1]:
                        UpperCamelCase_     ,      UpperCamelCase_					: List[str]            =				input_list[i + 1], input_list[i]
                        # swapping if elements not in order
                        UpperCamelCase_					: Dict            =				False
      return input_list


if __name__ == "__main__":
      print("Enter list to be sorted")
      UpperCamelCase      					=[int(x) for x in input().split()]
      # inputing elements of the list in one line
      UpperCamelCase      					=odd_even_sort(input_list)
      print("The sorted list is")
      print(sorted_list)






