



from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
__lowerCamelCase         =			Lock()







def    _snake_case (       __snake_case					,  __snake_case					,  __snake_case					,  __snake_case					,  __snake_case					,  __snake_case					,  __snake_case    )     ->     List[Any]:






      '''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					,  1_0    ):
            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(__snake_case    )
                  process_lock.release()

                  # receive your right neighbor's value
                  process_lock.acquire()
                  UpperCAmelCase_  :	Tuple				      =		rr_cv[0].recv()
                  process_lock.release()

                  # take the lower value since you are on the left
                  UpperCAmelCase_  :	Union[str, Any]				      =		min(__snake_case					,  __snake_case    )
            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(__snake_case    )
                  process_lock.release()

                  # receive your left neighbor's value
                  process_lock.acquire()
                  UpperCAmelCase_  :	Union[str, Any]				      =		lr_cv[0].recv()
                  process_lock.release()

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







def    _snake_case (       __snake_case    )     ->     Tuple:






      '''simple docstring'''







      UpperCAmelCase_  :	Union[str, Any]				      =		[]
      UpperCAmelCase_  :	Tuple				      =		[]
      # 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_  :	Tuple				      =		Pipe()
      process_array_.append(
          Process(
              target=__snake_case					,  args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0])					,  )    )
      UpperCAmelCase_  :	Tuple				      =		temp_rs
      UpperCAmelCase_  :	Optional[Any]				      =		temp_rr

      for i in range(1					,  len(__snake_case    ) - 1    ):
            UpperCAmelCase_  :	List[Any]				      =		Pipe()
            UpperCAmelCase_  :	List[str]				      =		Pipe()
            process_array_.append(
                Process(
                    target=__snake_case					,  args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i])					,  )    )
            UpperCAmelCase_  :	Optional[Any]				      =		temp_rs
            UpperCAmelCase_  :	List[str]				      =		temp_rr

      process_array_.append(
          Process(
              target=__snake_case					,  args=(
                  len(__snake_case    ) - 1,
                  arr[len(__snake_case    ) - 1],
                  temp_ls,
                  None,
                  temp_lr,
                  None,
                  result_pipe[len(__snake_case    ) - 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(__snake_case    )    ):
            UpperCAmelCase_  :	Optional[Any]				      =		result_pipe[p][0].recv()
            process_array_[p].join()
      return arr







def    _snake_case (       )     ->     str:






      '''simple docstring'''







      UpperCAmelCase_  :	List[Any]				      =		list(range(1_0					,  0					,  -1    )    )
      print("Initial List"    )
      print(*__snake_case    )
      UpperCAmelCase_  :	int				      =		odd_even_transposition(__snake_case    )
      print("Sorted List\n"    )
      print(*__snake_case    )


if __name__ == "__main__":
   main()





import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()







def    _snake_case (       __snake_case					,  __snake_case					,  __snake_case					,  __snake_case    )     ->     Optional[Any]:






      '''simple docstring'''







      UpperCAmelCase_  :	List[str]				      =		FunnelConfig.from_json_file(__snake_case    )
      print(F"""Building PyTorch model from configuration: {config}"""    )
      UpperCAmelCase_  :	str				      =		FunnelBaseModel(__snake_case    ) if base_model else FunnelModel(__snake_case    )

      # Load weights from tf checkpoint
      load_tf_weights_in_funnel(__snake_case					,  __snake_case					,  __snake_case    )

      # Save pytorch-model
      print(F"""Save PyTorch model to {pytorch_dump_path}"""    )
      torch.save(model.state_dict()					,  __snake_case    )


if __name__ == "__main__":
   __lowerCamelCase         =			argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       '''--tf_checkpoint_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
   )
   parser.add_argument(
       '''--config_file''',
       default=None,
       type=str,
       required=True,
       help='''The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.''',
   )
   parser.add_argument(
       '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
   )
   parser.add_argument(
       '''--base_model''', action='''store_true''', help='''Whether you want just the base model (no decoder) or not.'''
   )
   __lowerCamelCase         =			parser.parse_args()
   convert_tf_checkpoint_to_pytorch(
       args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
   )
