





import unittest

from transformers import TrOCRConfig
from transformers.testing_utils import is_torch_available, require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers.models.trocr.modeling_trocr import TrOCRDecoder, TrOCRForCausalLM





@require_torch
class 				A_				:







       """simple docstring"""





       def __init__(    self	:	str						,__A	:	Optional[Any]						,__A	:	str=99						,__A	:	List[Any]=13						,__A	:	Any=16						,__A	:	Optional[int]=7						,__A	:	Dict=True						,__A	:	int=True						,__A	:	Optional[int]=True						,__A	:	Union[str, Any]=False						,__A	:	List[Any]=True						,__A	:	int=2						,__A	:	List[Any]=32						,__A	:	Tuple=4						,__A	:	List[Any]=4						,__A	:	Optional[int]=30						,__A	:	Optional[Any]=0						,__A	:	int=1						,__A	:	Optional[int]=2						,__A	:	Union[str, Any]=None						,)						->					Dict:
         _lowercase							= parent
         _lowercase							= batch_size
         _lowercase							= decoder_seq_length
         # For common tests
         _lowercase							= self.decoder_seq_length
         _lowercase							= is_training
         _lowercase							= use_attention_mask
         _lowercase							= use_labels

         _lowercase							= vocab_size
         _lowercase							= d_model
         _lowercase							= d_model
         _lowercase							= decoder_layers
         _lowercase							= decoder_layers
         _lowercase							= decoder_ffn_dim
         _lowercase							= decoder_attention_heads
         _lowercase							= decoder_attention_heads
         _lowercase							= eos_token_id
         _lowercase							= bos_token_id
         _lowercase							= pad_token_id
         _lowercase							= decoder_start_token_id
         _lowercase							= use_cache
         _lowercase							= max_position_embeddings

         _lowercase							= None
         _lowercase							= decoder_seq_length
         _lowercase							= 2
         _lowercase							= 1







       def    __UpperCAmelCase (    self	:	List[str]  )						->					List[str]:
         _lowercase							= ids_tensor([self.batch_size, self.decoder_seq_length]						,self.vocab_size  )

         _lowercase							= None
         if self.use_attention_mask:
           _lowercase							= ids_tensor([self.batch_size, self.decoder_seq_length]						,vocab_size=2  )

         _lowercase							= None
         if self.use_labels:
           _lowercase							= ids_tensor([self.batch_size, self.decoder_seq_length]						,self.vocab_size  )

         _lowercase							= TrOCRConfig(
             vocab_size=self.vocab_size						,d_model=self.d_model						,decoder_layers=self.decoder_layers						,decoder_ffn_dim=self.decoder_ffn_dim						,decoder_attention_heads=self.decoder_attention_heads						,eos_token_id=self.eos_token_id						,bos_token_id=self.bos_token_id						,use_cache=self.use_cache						,pad_token_id=self.pad_token_id						,decoder_start_token_id=self.decoder_start_token_id						,max_position_embeddings=self.max_position_embeddings						,)

         return (config, input_ids, attention_mask, lm_labels)







       def    __UpperCAmelCase (    self	:	Any						,__A	:	Union[str, Any]						,__A	:	int						,__A	:	Any						,__A	:	Optional[Any]						,)						->					List[Any]:
         _lowercase							= True
         _lowercase							= TrOCRDecoder(config=__A  ).to(__A  ).eval()
         _lowercase							= input_ids[:2]

         input_ids[input_ids == 0] += 1
         # first forward pass
         _lowercase							= model(__A						,use_cache=__A  )
         _lowercase							= model(__A  )
         _lowercase							= model(__A						,use_cache=__A  )

         self.parent.assertTrue(len(__A  ) == len(__A  )  )
         self.parent.assertTrue(len(__A  ) == len(__A  ) + 1  )

         _lowercase							= outputs['past_key_values']

         # create hypothetical next token and extent to next_input_ids
         _lowercase							= ids_tensor((2, 1)						,config.vocab_size - 1  ) + 1

         # append to next input_ids and
         _lowercase							= torch.cat([input_ids, next_tokens]						,dim=-1  )

         _lowercase							= model(__A  )['last_hidden_state']
         _lowercase							= model(__A						,past_key_values=__A  )['last_hidden_state']

         # select random slice
         _lowercase							= ids_tensor((1,)						,output_from_past.shape[-1]  ).item()
         _lowercase							= output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
         _lowercase							= output_from_past[:, 0, random_slice_idx].detach()

         # test that outputs are equal for slice
         assert torch.allclose(__A						,__A						,atol=1e-3  )







       def    __UpperCAmelCase (    self	:	Optional[int]  )						->					str:
         _lowercase							= self.prepare_config_and_inputs()
         _lowercase						,		_lowercase						,		_lowercase						,		_lowercase							= config_and_inputs

         _lowercase							= {'input_ids': input_ids, 'attention_mask': attention_mask}
         return config, inputs_dict





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







       """simple docstring"""





       SCREAMING_SNAKE_CASE_      : str      =  (TrOCRDecoder, TrOCRForCausalLM) if is_torch_available() else ()
       SCREAMING_SNAKE_CASE_      : int      =  (TrOCRForCausalLM,) if is_torch_available() else ()
       SCREAMING_SNAKE_CASE_      : str      =  {'''text-generation''': TrOCRForCausalLM} if is_torch_available() else {}
       SCREAMING_SNAKE_CASE_      : Dict      =  True
       SCREAMING_SNAKE_CASE_      : Tuple      =  False







       def    __UpperCAmelCase (    self	:	Union[str, Any]  )						->					Tuple:
         _lowercase							= TrOCRStandaloneDecoderModelTester(self						,is_training=__A  )
         _lowercase							= ConfigTester(self						,config_class=__A  )







       def    __UpperCAmelCase (    self	:	Optional[Any]  )						->					Dict:
         pass







       def    __UpperCAmelCase (    self	:	str  )						->					Union[str, Any]:
         pass







       def    __UpperCAmelCase (    self	:	int  )						->					Dict:
         pass







       def    __UpperCAmelCase (    self	:	Optional[Any]  )						->					Optional[Any]:
         self.config_tester.run_common_tests()







       def    __UpperCAmelCase (    self	:	Dict  )						->					str:
         _lowercase							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_decoder_model_past(*__A  )







       def    __UpperCAmelCase (    self	:	Dict  )						->					Any:
         return







       @unittest.skip('The model doesn\'t support left padding'  )  # and it's not used enough to be worth fixing :)
       def    __UpperCAmelCase (    self	:	Dict  )						->					Any:
         pass






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))