


'''simple docstring'''



from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
__UpperCAmelCase      :Optional[Any]			    =       Lock()




def      _a     (						_lowercase :     Union[str, Any]      , _lowercase :     int      , _lowercase :     Tuple      , _lowercase :     Dict      , _lowercase :     Union[str, Any]      , _lowercase :     Dict      , _lowercase :     Tuple  ):





     '''simple docstring'''






     global process_lock

     # we perform n swaps since after n swaps we know we are sorted
     # we *could* stop early if we are sorted already, but it takes as long to
     # find out we are sorted as it does to sort the list with this algorithm
     for i in range(0      , 10  ):
          if (i + position) % 2 == 0 and r_send is not None:
               # send your value to your right neighbor
               process_lock.acquire()
               r_send[1].send(_lowercase  )
               process_lock.release()

               # receive your right neighbor's value
               process_lock.acquire()
               __UpperCAmelCase     :			Union[str, Any]  							=      rr_cv[0].recv()
               process_lock.release()

               # take the lower value since you are on the left
               __UpperCAmelCase     :			Union[str, Any]  							=      min(_lowercase      , _lowercase  )
          elif (i + position) % 2 != 0 and l_send is not None:
               # send your value to your left neighbor
               process_lock.acquire()
               l_send[1].send(_lowercase  )
               process_lock.release()

               # receive your left neighbor's value
               process_lock.acquire()
               __UpperCAmelCase     :			Dict  							=      lr_cv[0].recv()
               process_lock.release()

               # take the higher value since you are on the right
               __UpperCAmelCase     :			int  							=      max(_lowercase      , _lowercase  )
    # after all swaps are performed, send the values back to main
     result_pipe[1].send(_lowercase  )




def      _a     (						_lowercase :     Tuple  ):





     '''simple docstring'''






     __UpperCAmelCase     :			str  							=      []
     __UpperCAmelCase     :			Dict  							=      []
     # initialize the list of pipes where the values will be retrieved
     for _ in arr:
          result_pipe.append(Pipe()  )
     # creates the processes
     # the first and last process only have one neighbor so they are made outside
     # of the loop
     __UpperCAmelCase     :			int  							=      Pipe()
     __UpperCAmelCase     :			List[Any]  							=      Pipe()
     process_array_.append(
         Process(
             target=_lowercase      , args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0])      , )  )
     __UpperCAmelCase     :			Union[str, Any]  							=      temp_rs
     __UpperCAmelCase     :			int  							=      temp_rr

     for i in range(1      , len(_lowercase  ) - 1  ):
          __UpperCAmelCase     :			Dict  							=      Pipe()
          __UpperCAmelCase     :			str  							=      Pipe()
          process_array_.append(
              Process(
                  target=_lowercase      , args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i])      , )  )
          __UpperCAmelCase     :			int  							=      temp_rs
          __UpperCAmelCase     :			Union[str, Any]  							=      temp_rr

     process_array_.append(
         Process(
             target=_lowercase      , args=(
                 len(_lowercase  ) - 1,
                 arr[len(_lowercase  ) - 1],
                 temp_ls,
                 None,
                 temp_lr,
                 None,
                 result_pipe[len(_lowercase  ) - 1],
             )      , )  )

     # start the processes
     for p in process_array_:
          p.start()

     # wait for the processes to end and write their values to the list
     for p in range(0      , len(_lowercase  )  ):
          __UpperCAmelCase     :			Optional[Any]  							=      result_pipe[p][0].recv()
          process_array_[p].join()
     return arr




def      _a     (						):





     '''simple docstring'''






     __UpperCAmelCase     :			List[Any]  							=      list(range(10      , 0      , -1  )  )
     print('''Initial List'''  )
     print(*_lowercase  )
     __UpperCAmelCase     :			List[Any]  							=      odd_even_transposition(_lowercase  )
     print('''Sorted List\n'''  )
     print(*_lowercase  )


if __name__ == "__main__":
   main()



'''simple docstring'''



import unittest

from transformers import AlbertConfig, 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, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          MODEL_FOR_PRETRAINING_MAPPING,
          AlbertForMaskedLM,
          AlbertForMultipleChoice,
          AlbertForPreTraining,
          AlbertForQuestionAnswering,
          AlbertForSequenceClassification,
          AlbertForTokenClassification,
          AlbertModel,
      )
      from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST



class      a    :


     """simple docstring"""






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

     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							Optional[Any]:
          __UpperCAmelCase     :			int  							=      ids_tensor([self.batch_size, self.seq_length]							,			self.vocab_size      )

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

          __UpperCAmelCase     :			Dict  							=      None
          if self.use_token_type_ids:
               __UpperCAmelCase     :			Optional[Any]  							=      ids_tensor([self.batch_size, self.seq_length]							,			self.type_vocab_size      )

          __UpperCAmelCase     :			int  							=      None
          __UpperCAmelCase     :			List[str]  							=      None
          __UpperCAmelCase     :			Optional[Any]  							=      None
          if self.use_labels:
               __UpperCAmelCase     :			str  							=      ids_tensor([self.batch_size]							,			self.type_sequence_label_size      )
               __UpperCAmelCase     :			List[Any]  							=      ids_tensor([self.batch_size, self.seq_length]							,			self.num_labels      )
               __UpperCAmelCase     :			Optional[Any]  							=      ids_tensor([self.batch_size]							,			self.num_choices      )

          __UpperCAmelCase     :			List[str]  							=      self.get_config()

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

     def 			lowerCamelCase__			(    self					:		List[str]      )						->							Optional[Any]:
          return AlbertConfig(
              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							,			num_hidden_groups=self.num_hidden_groups							,			)

     def 			lowerCamelCase__			(    self					:		Tuple							,			snake_case					:		Optional[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		List[Any]							,			snake_case					:		Optional[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		Union[str, Any]							,			snake_case					:		int      )						->							Optional[int]:
          __UpperCAmelCase     :			List[Any]  							=      AlbertModel(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Tuple  							=      model(snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case      )
          __UpperCAmelCase     :			List[str]  							=      model(snake_case							,			token_type_ids=snake_case      )
          __UpperCAmelCase     :			str  							=      model(snake_case      )
          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 			lowerCamelCase__			(    self					:		List[str]							,			snake_case					:		str							,			snake_case					:		Optional[int]							,			snake_case					:		List[Any]							,			snake_case					:		Any							,			snake_case					:		Dict							,			snake_case					:		Dict							,			snake_case					:		Optional[int]      )						->							Optional[int]:
          __UpperCAmelCase     :			str  							=      AlbertForPreTraining(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Union[str, Any]  							=      model(
              snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case							,			labels=snake_case							,			sentence_order_label=snake_case							,			)
          self.parent.assertEqual(result.prediction_logits.shape							,			(self.batch_size, self.seq_length, self.vocab_size)      )
          self.parent.assertEqual(result.sop_logits.shape							,			(self.batch_size, config.num_labels)      )

     def 			lowerCamelCase__			(    self					:		Dict							,			snake_case					:		Union[str, Any]							,			snake_case					:		Dict							,			snake_case					:		Any							,			snake_case					:		Tuple							,			snake_case					:		Union[str, Any]							,			snake_case					:		Any							,			snake_case					:		Tuple      )						->							Union[str, Any]:
          __UpperCAmelCase     :			Dict  							=      AlbertForMaskedLM(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			str  							=      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					:		str							,			snake_case					:		Tuple							,			snake_case					:		List[str]							,			snake_case					:		Union[str, Any]							,			snake_case					:		List[str]							,			snake_case					:		Tuple							,			snake_case					:		Optional[Any]							,			snake_case					:		Tuple      )						->							int:
          __UpperCAmelCase     :			Optional[Any]  							=      AlbertForQuestionAnswering(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Optional[Any]  							=      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					:		List[str]							,			snake_case					:		Dict							,			snake_case					:		Optional[int]							,			snake_case					:		Dict							,			snake_case					:		int							,			snake_case					:		Optional[int]							,			snake_case					:		Optional[Any]      )						->							Any:
          __UpperCAmelCase     :			Optional[int]  							=      self.num_labels
          __UpperCAmelCase     :			Any  							=      AlbertForSequenceClassification(snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			str  							=      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					:		Tuple							,			snake_case					:		Tuple							,			snake_case					:		List[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		str							,			snake_case					:		Dict							,			snake_case					:		Union[str, Any]							,			snake_case					:		List[str]      )						->							int:
          __UpperCAmelCase     :			Optional[int]  							=      self.num_labels
          __UpperCAmelCase     :			Optional[int]  							=      AlbertForTokenClassification(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			str  							=      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					:		Tuple							,			snake_case					:		Tuple							,			snake_case					:		List[Any]							,			snake_case					:		Dict							,			snake_case					:		int							,			snake_case					:		List[Any]							,			snake_case					:		List[Any]							,			snake_case					:		Optional[Any]      )						->							Tuple:
          __UpperCAmelCase     :			Optional[int]  							=      self.num_choices
          __UpperCAmelCase     :			List[Any]  							=      AlbertForMultipleChoice(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Dict  							=      input_ids.unsqueeze(1      ).expand(-1							,			self.num_choices							,			-1      ).contiguous()
          __UpperCAmelCase     :			List[Any]  							=      token_type_ids.unsqueeze(1      ).expand(-1							,			self.num_choices							,			-1      ).contiguous()
          __UpperCAmelCase     :			List[Any]  							=      input_mask.unsqueeze(1      ).expand(-1							,			self.num_choices							,			-1      ).contiguous()
          __UpperCAmelCase     :			List[str]  							=      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					:		Union[str, Any]      )						->							Any:
          __UpperCAmelCase     :			List[Any]  							=      self.prepare_config_and_inputs()
          (
              (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       
          )     :			List[Any]  							=      config_and_inputs
          __UpperCAmelCase     :			List[str]  							=      {'''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"""






     SCREAMING_SNAKE_CASE	:			Tuple							       =       (
         (
             AlbertModel,
             AlbertForPreTraining,
             AlbertForMaskedLM,
             AlbertForMultipleChoice,
             AlbertForSequenceClassification,
             AlbertForTokenClassification,
             AlbertForQuestionAnswering,
         )
         if is_torch_available()
         else ()
     )
     SCREAMING_SNAKE_CASE	:			Any							       =       (
         {
             "feature-extraction": AlbertModel,
             "fill-mask": AlbertForMaskedLM,
             "question-answering": AlbertForQuestionAnswering,
             "text-classification": AlbertForSequenceClassification,
             "token-classification": AlbertForTokenClassification,
             "zero-shot": AlbertForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     SCREAMING_SNAKE_CASE	:			Any							       =       True

     def 			lowerCamelCase__			(    self					:		Optional[int]							,			snake_case					:		Any							,			snake_case					:		Dict							,			snake_case					:		Tuple=False      )						->							Optional[Any]:
          __UpperCAmelCase     :			Any  							=      super()._prepare_for_class(snake_case							,			snake_case							,			return_labels=snake_case      )

          if return_labels:
               if model_class in get_values(snake_case      ):
                    __UpperCAmelCase     :			Dict  							=      torch.zeros(
                        (self.model_tester.batch_size, self.model_tester.seq_length)							,			dtype=torch.long							,			device=snake_case      )
                    __UpperCAmelCase     :			Union[str, Any]  							=      torch.zeros(
                        self.model_tester.batch_size							,			dtype=torch.long							,			device=snake_case      )
          return inputs_dict

     def 			lowerCamelCase__			(    self					:		Dict      )						->							int:
          __UpperCAmelCase     :			List[Any]  							=      AlbertModelTester(self      )
          __UpperCAmelCase     :			Any  							=      ConfigTester(self							,			config_class=snake_case							,			hidden_size=37      )

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

     def 			lowerCamelCase__			(    self					:		Any      )						->							Any:
          __UpperCAmelCase     :			Union[str, Any]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Any      )						->							Optional[Any]:
          __UpperCAmelCase     :			Optional[int]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Optional[int]      )						->							Optional[Any]:
          __UpperCAmelCase     :			Optional[int]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Union[str, Any]      )						->							Tuple:
          __UpperCAmelCase     :			Dict  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Dict      )						->							str:
          __UpperCAmelCase     :			Union[str, Any]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*snake_case      )

     def 			lowerCamelCase__			(    self					:		List[str]      )						->							Tuple:
          __UpperCAmelCase     :			Any  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*snake_case      )

     def 			lowerCamelCase__			(    self					:		str      )						->							Any:
          __UpperCAmelCase     :			int  							=      self.model_tester.prepare_config_and_inputs()
          for type in ["absolute", "relative_key", "relative_key_query"]:
               __UpperCAmelCase     :			Tuple  							=      type
               self.model_tester.create_and_check_model(*snake_case      )






     @slow
     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Optional[int]:
          for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __UpperCAmelCase     :			List[Any]  							=      AlbertModel.from_pretrained(snake_case      )
               self.assertIsNotNone(snake_case      )



@require_torch
class      a    (		unittest.TestCase	):


     """simple docstring"""






     @slow
     def 			lowerCamelCase__			(    self					:		Optional[Any]      )						->							Union[str, Any]:
          __UpperCAmelCase     :			Optional[int]  							=      AlbertModel.from_pretrained('''albert-base-v2'''      )
          __UpperCAmelCase     :			str  							=      torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]      )
          __UpperCAmelCase     :			List[Any]  							=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
          with torch.no_grad():
               __UpperCAmelCase     :			Optional[int]  							=      model(snake_case							,			attention_mask=snake_case      )[0]
          __UpperCAmelCase     :			Any  							=      torch.Size((1, 11, 768)      )
          self.assertEqual(output.shape							,			snake_case      )
          __UpperCAmelCase     :			int  							=      torch.tensor(
              [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]      )

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