


from multiprocessing import Lock, Pipe, Process

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






def 							__lowercase   ( __lowerCAmelCase							:				Tuple					,    __lowerCAmelCase							:				List[Any]					,    __lowerCAmelCase							:				int					,    __lowerCAmelCase							:				List[Any]					,    __lowerCAmelCase							:				List[str]					,    __lowerCAmelCase							:				Optional[Any]					,    __lowerCAmelCase							:				int   ):
							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(__lowerCAmelCase   )
																					process_lock.release()

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

																					# take the lower value since you are on the left
																					a__             =     min(__lowerCAmelCase					,    __lowerCAmelCase   )
														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(__lowerCAmelCase   )
																					process_lock.release()

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

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






def 							__lowercase   ( __lowerCAmelCase							:				Union[str, Any]   ):
							a__             =     []
							a__             =     []
							# 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
							a__             =     Pipe()
							a__             =     Pipe()
							process_array_.append(
							    Process(
							        target=__lowerCAmelCase					,    args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0])					,    )   )
							a__             =     temp_rs
							a__             =     temp_rr

							for i in range(1					,    len(__lowerCAmelCase   ) - 1   ):
														a__             =     Pipe()
														a__             =     Pipe()
														process_array_.append(
														    Process(
														        target=__lowerCAmelCase					,    args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i])					,    )   )
														a__             =     temp_rs
														a__             =     temp_rr

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






def 							__lowercase   ( ):
							a__             =     list(range(1_0					,    0					,    -1   )   )
							print('Initial List'   )
							print(*__lowerCAmelCase   )
							a__             =     odd_even_transposition(__lowerCAmelCase   )
							print('Sorted List\n'   )
							print(*__lowerCAmelCase   )


if __name__ == "__main__":
						main()








import argparse

import torch

from transformers import GPTaConfig, GPTaModel, load_tf_weights_in_gpta
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()






def 							__lowercase   ( __lowerCAmelCase							:				str					,    __lowerCAmelCase							:				Any					,    __lowerCAmelCase							:				int   ):
							# Construct model
							if gpta_config_file == "":
														a__             =     GPTaConfig()
							else:
														a__             =     GPTaConfig.from_json_file(__lowerCAmelCase   )
							a__             =     GPTaModel(__lowerCAmelCase   )

							# Load weights from numpy
							load_tf_weights_in_gpta(__lowerCAmelCase					,    __lowerCAmelCase					,    __lowerCAmelCase   )

							# Save pytorch-model
							a__             =     pytorch_dump_folder_path + '/' + WEIGHTS_NAME
							a__             =     pytorch_dump_folder_path + '/' + CONFIG_NAME
							print(F'Save PyTorch model to {pytorch_weights_dump_path}'   )
							torch.save(model.state_dict()					,    __lowerCAmelCase   )
							print(F'Save configuration file to {pytorch_config_dump_path}'   )
							with open(__lowerCAmelCase					,    'w'					,    encoding='utf-8'   ) as f:
														f.write(config.to_json_string()   )


if __name__ == "__main__":
						snake_case							:       List[Any]     			=      argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    '''--gpt2_checkpoint_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
						)
						parser.add_argument(
						    '''--pytorch_dump_folder_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
						)
						parser.add_argument(
						    '''--gpt2_config_file''',
						    default='''''',
						    type=str,
						    help=(
						        '''An optional config json file corresponding to the pre-trained OpenAI model. \n'''
						        '''This specifies the model architecture.'''
						    ),
						)
						snake_case							:       Any     			=      parser.parse_args()
						convert_gpta_checkpoint_to_pytorch(args.gpta_checkpoint_path, args.gpta_config_file, args.pytorch_dump_folder_path)




