





import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
      import torch

      from transformers import (
          MODEL_FOR_PRETRAINING_MAPPING,
          MobileBertForMaskedLM,
          MobileBertForMultipleChoice,
          MobileBertForNextSentencePrediction,
          MobileBertForPreTraining,
          MobileBertForQuestionAnswering,
          MobileBertForSequenceClassification,
          MobileBertForTokenClassification,
          MobileBertModel,
      )





class 				A_				:







       """simple docstring"""





       def __init__(    self	:	int						,__A	:	str						,__A	:	Optional[int]=13						,__A	:	Tuple=7						,__A	:	List[str]=True						,__A	:	Optional[Any]=True						,__A	:	Union[str, Any]=True						,__A	:	List[Any]=True						,__A	:	List[str]=99						,__A	:	Union[str, Any]=64						,__A	:	int=32						,__A	:	Optional[int]=5						,__A	:	Dict=4						,__A	:	Optional[Any]=37						,__A	:	Dict="gelu"						,__A	:	List[Any]=0.1						,__A	:	Dict=0.1						,__A	:	str=512						,__A	:	List[str]=16						,__A	:	List[Any]=2						,__A	:	List[Any]=0.02						,__A	:	Any=3						,__A	:	Optional[int]=4						,__A	:	Dict=None						,)						->					Dict:
         _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							= embedding_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







       def    __UpperCAmelCase (    self	:	Dict  )						->					int:
         _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							= self.get_config()

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







       def    __UpperCAmelCase (    self	:	Optional[int]  )						->					Tuple:
         return 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						,embedding_size=self.embedding_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    __UpperCAmelCase (    self	:	Optional[Any]						,__A	:	Any						,__A	:	List[str]						,__A	:	Dict						,__A	:	Optional[int]						,__A	:	List[Any]						,__A	:	List[Any]						,__A	:	List[Any]  )						->					Optional[Any]:
         _lowercase							= MobileBertModel(config=__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= model(__A						,attention_mask=__A						,token_type_ids=__A  )
         _lowercase							= model(__A						,token_type_ids=__A  )
         _lowercase							= model(__A  )

         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	:	Optional[Any]						,__A	:	List[str]						,__A	:	List[Any]						,__A	:	Optional[Any]						,__A	:	Dict						,__A	:	Tuple						,__A	:	List[Any]						,__A	:	int  )						->					List[Any]:
         _lowercase							= MobileBertForMaskedLM(config=__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= 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    __UpperCAmelCase (    self	:	List[Any]						,__A	:	Optional[int]						,__A	:	Optional[Any]						,__A	:	List[Any]						,__A	:	List[Any]						,__A	:	Union[str, Any]						,__A	:	Optional[Any]						,__A	:	List[Any]  )						->					Union[str, Any]:
         _lowercase							= MobileBertForNextSentencePrediction(config=__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= model(
             __A						,attention_mask=__A						,token_type_ids=__A						,labels=__A						,)
         self.parent.assertEqual(result.logits.shape						,(self.batch_size, 2)  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	Union[str, Any]						,__A	:	List[str]						,__A	:	Optional[Any]						,__A	:	Optional[Any]						,__A	:	Tuple						,__A	:	str						,__A	:	List[Any]  )						->					int:
         _lowercase							= MobileBertForPreTraining(config=__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= model(
             __A						,attention_mask=__A						,token_type_ids=__A						,labels=__A						,next_sentence_label=__A						,)
         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	:	Dict						,__A	:	Any						,__A	:	Optional[int]						,__A	:	Optional[Any]						,__A	:	Optional[int]						,__A	:	str						,__A	:	Any						,__A	:	Optional[int]  )						->					Dict:
         _lowercase							= MobileBertForQuestionAnswering(config=__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= 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    __UpperCAmelCase (    self	:	List[Any]						,__A	:	Optional[Any]						,__A	:	List[str]						,__A	:	Optional[Any]						,__A	:	Dict						,__A	:	List[str]						,__A	:	List[str]						,__A	:	int  )						->					Optional[int]:
         _lowercase							= self.num_labels
         _lowercase							= MobileBertForSequenceClassification(__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= model(__A						,attention_mask=__A						,token_type_ids=__A						,labels=__A  )
         self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.num_labels)  )







       def    __UpperCAmelCase (    self	:	List[Any]						,__A	:	Optional[int]						,__A	:	int						,__A	:	Dict						,__A	:	Union[str, Any]						,__A	:	str						,__A	:	Optional[Any]						,__A	:	List[Any]  )						->					Any:
         _lowercase							= self.num_labels
         _lowercase							= MobileBertForTokenClassification(config=__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= 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    __UpperCAmelCase (    self	:	Dict						,__A	:	Optional[Any]						,__A	:	List[Any]						,__A	:	int						,__A	:	List[str]						,__A	:	Any						,__A	:	Optional[int]						,__A	:	int  )						->					Optional[int]:
         _lowercase							= self.num_choices
         _lowercase							= MobileBertForMultipleChoice(config=__A  )
         model.to(__A  )
         model.eval()
         _lowercase							= input_ids.unsqueeze(1  ).expand(-1						,self.num_choices						,-1  ).contiguous()
         _lowercase							= token_type_ids.unsqueeze(1  ).expand(-1						,self.num_choices						,-1  ).contiguous()
         _lowercase							= input_mask.unsqueeze(1  ).expand(-1						,self.num_choices						,-1  ).contiguous()
         _lowercase							= model(
             __A						,attention_mask=__A						,token_type_ids=__A						,labels=__A						,)
         self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.num_choices)  )







       def    __UpperCAmelCase (    self	:	int  )						->					Any:
         _lowercase							= self.prepare_config_and_inputs()
         (
             (
             _lowercase
         )						,		(
             _lowercase
         )						,		(
             _lowercase
         )						,		(
             _lowercase
         )						,		(
             _lowercase
         )						,		(
             _lowercase
         )						,		(
             _lowercase
         )						,		
         )							= config_and_inputs
         _lowercase							= {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
         return config, inputs_dict





@require_torch
class 				A_				(      UpperCAmelCase					,	UpperCAmelCase					,	unittest.TestCase	):







       """simple docstring"""





       SCREAMING_SNAKE_CASE_      : List[Any]      =  (
           (
               MobileBertModel,
               MobileBertForMaskedLM,
               MobileBertForMultipleChoice,
               MobileBertForNextSentencePrediction,
               MobileBertForPreTraining,
               MobileBertForQuestionAnswering,
               MobileBertForSequenceClassification,
               MobileBertForTokenClassification,
           )
           if is_torch_available()
           else ()
       )
       SCREAMING_SNAKE_CASE_      : Tuple      =  (
           {
               '''feature-extraction''': MobileBertModel,
               '''fill-mask''': MobileBertForMaskedLM,
               '''question-answering''': MobileBertForQuestionAnswering,
               '''text-classification''': MobileBertForSequenceClassification,
               '''token-classification''': MobileBertForTokenClassification,
               '''zero-shot''': MobileBertForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
       SCREAMING_SNAKE_CASE_      : str      =  True







       def    __UpperCAmelCase (    self	:	int						,__A	:	str						,__A	:	Optional[Any]						,__A	:	int=False  )						->					Dict:
         _lowercase							= super()._prepare_for_class(__A						,__A						,return_labels=__A  )

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







       def    __UpperCAmelCase (    self	:	List[str]  )						->					Dict:
         _lowercase							= MobileBertModelTester(self  )
         _lowercase							= ConfigTester(self						,config_class=__A						,hidden_size=37  )







       def    __UpperCAmelCase (    self	:	Dict  )						->					Any:
         self.config_tester.run_common_tests()







       def    __UpperCAmelCase (    self	:	Union[str, Any]  )						->					Any:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_model(*__A  )







       def    __UpperCAmelCase (    self	:	Union[str, Any]  )						->					Tuple:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_masked_lm(*__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]  )						->					List[str]:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__A  )







       def    __UpperCAmelCase (    self	:	str  )						->					Optional[int]:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]  )						->					Union[str, Any]:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_pretraining(*__A  )







       def    __UpperCAmelCase (    self	:	List[Any]  )						->					List[str]:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_question_answering(*__A  )







       def    __UpperCAmelCase (    self	:	Any  )						->					Union[str, Any]:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__A  )







       def    __UpperCAmelCase (    self	:	Tuple  )						->					Any:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_token_classification(*__A  )

def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :Optional[Any]     )      ->						int:
  return torch.tensor(
      snake_case__			,							dtype=torch.long			,							device=snake_case__			,							)


snake_case 				=       1e-3







@require_torch
@require_sentencepiece
@require_tokenizers
class 				A_				(      unittest.TestCase	):







       """simple docstring"""





       @slow
       def    __UpperCAmelCase (    self	:	List[Any]  )						->					int:
         _lowercase							= MobileBertModel.from_pretrained('google/mobilebert-uncased'  ).to(__A  )
         _lowercase							= _long_tensor([[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]  )
         with torch.no_grad():
           _lowercase							= model(__A  )[0]
         _lowercase							= torch.Size((1, 9, 512)  )
         self.assertEqual(output.shape						,__A  )
         _lowercase							= torch.tensor(
             [
                 [
                     [-2.4_73_65_26e07, 8.2_69_16_56e04, 1.6_52_18_38e05],
                     [-5.7_54_17_04e-01, 3.9_05_60_22e00, 4.4_01_15_07e00],
                     [2.6_04_73_59e00, 1.5_67_76_52e00, -1.7_32_41_88e-01],
                 ]
             ]						,device=__A						,)

         # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
         # ~1 difference, it's therefore not a good idea to measure using addition.
         # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
         # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
         _lowercase							= torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE  )
         _lowercase							= torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE  )

         self.assertTrue(lower_bound and upper_bound  )






def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :List[str]     )      ->						Dict:
  _lowercase							= len(snake_case__     )
  while cur > 1:
    # Find the maximum number in arr
    _lowercase							= arr.index(max(arr[0:cur]     )     )
    # Reverse from 0 to mi
    _lowercase							= arr[mi::-1] + arr[mi + 1 : len(snake_case__     )]
    # Reverse whole list
    _lowercase							= arr[cur - 1 :: -1] + arr[cur : len(snake_case__     )]
    cur -= 1
  return arr


if __name__ == "__main__":
      snake_case 				=       input("""Enter numbers separated by a comma:\n""").strip()
      snake_case 				=       [int(item) for item in user_input.split(""",""")]
      print(pancake_sort(unsorted))