


from collections import deque
from math import floor
from random import random
from time import time







class        snake_case_   :
					def __init__(      self   :Dict      )					->    List[Any]:
												a__             =     {}
					def  lowerCamelCase__(      self   :List[str]			,__snake_case   :int			,__snake_case   :List[Any]			,__snake_case   :int=1      )					->    Optional[int]:
												if self.graph.get(__snake_case      ):
																			if self.graph[u].count([w, v]      ) == 0:
																										self.graph[u].append([w, v]      )
												else:
																			a__             =     [[w, v]]
												if not self.graph.get(__snake_case      ):
																			a__             =     []
					def  lowerCamelCase__(      self   :str      )					->    List[Any]:
												return list(self.graph      )
					def  lowerCamelCase__(      self   :List[Any]			,__snake_case   :List[Any]			,__snake_case   :Optional[Any]      )					->    Any:
												if self.graph.get(__snake_case      ):
																			for _ in self.graph[u]:
																										if _[1] == v:
																																	self.graph[u].remove(__snake_case      )
					def  lowerCamelCase__(      self   :Any			,__snake_case   :Any=-2			,__snake_case   :Optional[int]=-1      )					->    Optional[Any]:
												if s == d:
																			return []
												a__             =     []
												a__             =     []
												if s == -2:
																			a__             =     list(self.graph      )[0]
												stack.append(__snake_case      )
												visited.append(__snake_case      )
												a__             =     s

												while True:
																			# check if there is any non isolated nodes
																			if len(self.graph[s]      ) != 0:
																										a__             =     s
																										for node in self.graph[s]:
																																	if visited.count(node[1]      ) < 1:
																																								if node[1] == d:
																																															visited.append(__snake_case      )
																																															return visited
																																								else:
																																															stack.append(node[1]      )
																																															visited.append(node[1]      )
																																															a__             =     node[1]
																																															break

            # check if all the children are visited
																			if s == ss:
																										stack.pop()
																										if len(__snake_case      ) != 0:
																																	a__             =     stack[len(__snake_case      ) - 1]
																			else:
																										a__             =     ss

																			# check if se have reached the starting point
																			if len(__snake_case      ) == 0:
																										return visited
					def  lowerCamelCase__(      self   :Dict			,__snake_case   :Any=-1      )					->    List[str]:
												if c == -1:
																			a__             =     floor(random() * 1_00_00      ) + 10
												for i in range(__snake_case      ):
																			# every vertex has max 100 edges
																			for _ in range(floor(random() * 1_02      ) + 1      ):
																										a__             =     floor(random() * c      ) + 1
																										if n != i:
																																	self.add_pair(__snake_case			,__snake_case			,1      )
					def  lowerCamelCase__(      self   :Optional[Any]			,__snake_case   :Optional[int]=-2      )					->    Optional[Any]:
												a__             =     deque()
												a__             =     []
												if s == -2:
																			a__             =     list(self.graph      )[0]
												d.append(__snake_case      )
												visited.append(__snake_case      )
												while d:
																			a__             =     d.popleft()
																			if len(self.graph[s]      ) != 0:
																										for node in self.graph[s]:
																																	if visited.count(node[1]      ) < 1:
																																								d.append(node[1]      )
																																								visited.append(node[1]      )
												return visited
					def  lowerCamelCase__(      self   :Optional[Any]			,__snake_case   :Optional[Any]      )					->    List[str]:
												a__             =     0
												for x in self.graph:
																			for y in self.graph[x]:
																										if y[1] == u:
																																	count += 1
												return count
					def  lowerCamelCase__(      self   :int			,__snake_case   :List[str]      )					->    int:
												return len(self.graph[u]      )
					def  lowerCamelCase__(      self   :List[str]			,__snake_case   :Any=-2      )					->    Union[str, Any]:
												a__             =     []
												a__             =     []
												if s == -2:
																			a__             =     list(self.graph      )[0]
												stack.append(__snake_case      )
												visited.append(__snake_case      )
												a__             =     s
												a__             =     []

												while True:
																			# check if there is any non isolated nodes
																			if len(self.graph[s]      ) != 0:
																										a__             =     s
																										for node in self.graph[s]:
																																	if visited.count(node[1]      ) < 1:
																																								stack.append(node[1]      )
																																								visited.append(node[1]      )
																																								a__             =     node[1]
																																								break

            # check if all the children are visited
																			if s == ss:
																										sorted_nodes.append(stack.pop()      )
																										if len(__snake_case      ) != 0:
																																	a__             =     stack[len(__snake_case      ) - 1]
																			else:
																										a__             =     ss

																			# check if se have reached the starting point
																			if len(__snake_case      ) == 0:
																										return sorted_nodes
					def  lowerCamelCase__(      self   :Any      )					->    Dict:
												a__             =     []
												a__             =     []
												a__             =     list(self.graph      )[0]
												stack.append(__snake_case      )
												visited.append(__snake_case      )
												a__             =     -2
												a__             =     []
												a__             =     s
												a__             =     False
												a__             =     set()

												while True:
																			# check if there is any non isolated nodes
																			if len(self.graph[s]      ) != 0:
																										a__             =     s
																										for node in self.graph[s]:
																																	if (
																																	    visited.count(node[1]      ) > 0
																																	    and node[1] != parent
																																	    and indirect_parents.count(node[1]      ) > 0
																																	    and not on_the_way_back
																																	):
																																								a__             =     len(__snake_case      ) - 1
																																								while len_stack >= 0:
																																															if stack[len_stack] == node[1]:
																																																						anticipating_nodes.add(node[1]      )
																																																						break
																																															else:
																																																						anticipating_nodes.add(stack[len_stack]      )
																																																						len_stack -= 1
																																	if visited.count(node[1]      ) < 1:
																																								stack.append(node[1]      )
																																								visited.append(node[1]      )
																																								a__             =     node[1]
																																								break

            # check if all the children are visited
																			if s == ss:
																										stack.pop()
																										a__             =     True
																										if len(__snake_case      ) != 0:
																																	a__             =     stack[len(__snake_case      ) - 1]
																			else:
																										a__             =     False
																										indirect_parents.append(__snake_case      )
																										a__             =     s
																										a__             =     ss

																			# check if se have reached the starting point
																			if len(__snake_case      ) == 0:
																										return list(__snake_case      )
					def  lowerCamelCase__(      self   :Optional[int]      )					->    str:
												a__             =     []
												a__             =     []
												a__             =     list(self.graph      )[0]
												stack.append(__snake_case      )
												visited.append(__snake_case      )
												a__             =     -2
												a__             =     []
												a__             =     s
												a__             =     False
												a__             =     set()

												while True:
																			# check if there is any non isolated nodes
																			if len(self.graph[s]      ) != 0:
																										a__             =     s
																										for node in self.graph[s]:
																																	if (
																																	    visited.count(node[1]      ) > 0
																																	    and node[1] != parent
																																	    and indirect_parents.count(node[1]      ) > 0
																																	    and not on_the_way_back
																																	):
																																								a__             =     len(__snake_case      ) - 1
																																								while len_stack_minus_one >= 0:
																																															if stack[len_stack_minus_one] == node[1]:
																																																						anticipating_nodes.add(node[1]      )
																																																						break
																																															else:
																																																						return True
																																	if visited.count(node[1]      ) < 1:
																																								stack.append(node[1]      )
																																								visited.append(node[1]      )
																																								a__             =     node[1]
																																								break

            # check if all the children are visited
																			if s == ss:
																										stack.pop()
																										a__             =     True
																										if len(__snake_case      ) != 0:
																																	a__             =     stack[len(__snake_case      ) - 1]
																			else:
																										a__             =     False
																										indirect_parents.append(__snake_case      )
																										a__             =     s
																										a__             =     ss

																			# check if se have reached the starting point
																			if len(__snake_case      ) == 0:
																										return False
					def  lowerCamelCase__(      self   :Any			,__snake_case   :Tuple=-2			,__snake_case   :Optional[int]=-1      )					->    str:
												a__             =     time()
												self.dfs(__snake_case			,__snake_case      )
												a__             =     time()
												return end - begin



					def  lowerCamelCase__(      self   :Dict			,__snake_case   :Optional[int]=-2      )					->    Optional[Any]:
												a__             =     time()
												self.bfs(__snake_case      )
												a__             =     time()
												return end - begin







class        snake_case_   :
					def __init__(      self   :List[Any]      )					->    Dict:
												a__             =     {}
					def  lowerCamelCase__(      self   :Optional[int]			,__snake_case   :Dict			,__snake_case   :int			,__snake_case   :Tuple=1      )					->    Optional[Any]:
												# check if the u exists
												if self.graph.get(__snake_case      ):
																			# if there already is a edge
																			if self.graph[u].count([w, v]      ) == 0:
																										self.graph[u].append([w, v]      )
												else:
																			# if u does not exist
																			a__             =     [[w, v]]
												# add the other way
												if self.graph.get(__snake_case      ):
																			# if there already is a edge
																			if self.graph[v].count([w, u]      ) == 0:
																										self.graph[v].append([w, u]      )
												else:
																			# if u does not exist
																			a__             =     [[w, u]]
					def  lowerCamelCase__(      self   :int			,__snake_case   :Union[str, Any]			,__snake_case   :Optional[int]      )					->    int:
												if self.graph.get(__snake_case      ):
																			for _ in self.graph[u]:
																										if _[1] == v:
																																	self.graph[u].remove(__snake_case      )
        # the other way round
												if self.graph.get(__snake_case      ):
																			for _ in self.graph[v]:
																										if _[1] == u:
																																	self.graph[v].remove(__snake_case      )
					def  lowerCamelCase__(      self   :Optional[Any]			,__snake_case   :int=-2			,__snake_case   :Any=-1      )					->    Optional[Any]:
												if s == d:
																			return []
												a__             =     []
												a__             =     []
												if s == -2:
																			a__             =     list(self.graph      )[0]
												stack.append(__snake_case      )
												visited.append(__snake_case      )
												a__             =     s

												while True:
																			# check if there is any non isolated nodes
																			if len(self.graph[s]      ) != 0:
																										a__             =     s
																										for node in self.graph[s]:
																																	if visited.count(node[1]      ) < 1:
																																								if node[1] == d:
																																															visited.append(__snake_case      )
																																															return visited
																																								else:
																																															stack.append(node[1]      )
																																															visited.append(node[1]      )
																																															a__             =     node[1]
																																															break

            # check if all the children are visited
																			if s == ss:
																										stack.pop()
																										if len(__snake_case      ) != 0:
																																	a__             =     stack[len(__snake_case      ) - 1]
																			else:
																										a__             =     ss

																			# check if se have reached the starting point
																			if len(__snake_case      ) == 0:
																										return visited
					def  lowerCamelCase__(      self   :int			,__snake_case   :Any=-1      )					->    Optional[int]:
												if c == -1:
																			a__             =     floor(random() * 1_00_00      ) + 10
												for i in range(__snake_case      ):
																			# every vertex has max 100 edges
																			for _ in range(floor(random() * 1_02      ) + 1      ):
																										a__             =     floor(random() * c      ) + 1
																										if n != i:
																																	self.add_pair(__snake_case			,__snake_case			,1      )
					def  lowerCamelCase__(      self   :Any			,__snake_case   :Optional[Any]=-2      )					->    Optional[int]:
												a__             =     deque()
												a__             =     []
												if s == -2:
																			a__             =     list(self.graph      )[0]
												d.append(__snake_case      )
												visited.append(__snake_case      )
												while d:
																			a__             =     d.popleft()
																			if len(self.graph[s]      ) != 0:
																										for node in self.graph[s]:
																																	if visited.count(node[1]      ) < 1:
																																								d.append(node[1]      )
																																								visited.append(node[1]      )
												return visited
					def  lowerCamelCase__(      self   :Tuple			,__snake_case   :Optional[Any]      )					->    List[str]:
												return len(self.graph[u]      )
					def  lowerCamelCase__(      self   :str      )					->    Optional[int]:
												a__             =     []
												a__             =     []
												a__             =     list(self.graph      )[0]
												stack.append(__snake_case      )
												visited.append(__snake_case      )
												a__             =     -2
												a__             =     []
												a__             =     s
												a__             =     False
												a__             =     set()

												while True:
																			# check if there is any non isolated nodes
																			if len(self.graph[s]      ) != 0:
																										a__             =     s
																										for node in self.graph[s]:
																																	if (
																																	    visited.count(node[1]      ) > 0
																																	    and node[1] != parent
																																	    and indirect_parents.count(node[1]      ) > 0
																																	    and not on_the_way_back
																																	):
																																								a__             =     len(__snake_case      ) - 1
																																								while len_stack >= 0:
																																															if stack[len_stack] == node[1]:
																																																						anticipating_nodes.add(node[1]      )
																																																						break
																																															else:
																																																						anticipating_nodes.add(stack[len_stack]      )
																																																						len_stack -= 1
																																	if visited.count(node[1]      ) < 1:
																																								stack.append(node[1]      )
																																								visited.append(node[1]      )
																																								a__             =     node[1]
																																								break

            # check if all the children are visited
																			if s == ss:
																										stack.pop()
																										a__             =     True
																										if len(__snake_case      ) != 0:
																																	a__             =     stack[len(__snake_case      ) - 1]
																			else:
																										a__             =     False
																										indirect_parents.append(__snake_case      )
																										a__             =     s
																										a__             =     ss

																			# check if se have reached the starting point
																			if len(__snake_case      ) == 0:
																										return list(__snake_case      )
					def  lowerCamelCase__(      self   :Optional[Any]      )					->    Tuple:
												a__             =     []
												a__             =     []
												a__             =     list(self.graph      )[0]
												stack.append(__snake_case      )
												visited.append(__snake_case      )
												a__             =     -2
												a__             =     []
												a__             =     s
												a__             =     False
												a__             =     set()

												while True:
																			# check if there is any non isolated nodes
																			if len(self.graph[s]      ) != 0:
																										a__             =     s
																										for node in self.graph[s]:
																																	if (
																																	    visited.count(node[1]      ) > 0
																																	    and node[1] != parent
																																	    and indirect_parents.count(node[1]      ) > 0
																																	    and not on_the_way_back
																																	):
																																								a__             =     len(__snake_case      ) - 1
																																								while len_stack_minus_one >= 0:
																																															if stack[len_stack_minus_one] == node[1]:
																																																						anticipating_nodes.add(node[1]      )
																																																						break
																																															else:
																																																						return True
																																	if visited.count(node[1]      ) < 1:
																																								stack.append(node[1]      )
																																								visited.append(node[1]      )
																																								a__             =     node[1]
																																								break

            # check if all the children are visited
																			if s == ss:
																										stack.pop()
																										a__             =     True
																										if len(__snake_case      ) != 0:
																																	a__             =     stack[len(__snake_case      ) - 1]
																			else:
																										a__             =     False
																										indirect_parents.append(__snake_case      )
																										a__             =     s
																										a__             =     ss

																			# check if se have reached the starting point
																			if len(__snake_case      ) == 0:
																										return False
					def  lowerCamelCase__(      self   :Optional[Any]      )					->    Union[str, Any]:
												return list(self.graph      )
					def  lowerCamelCase__(      self   :Union[str, Any]			,__snake_case   :str=-2			,__snake_case   :List[str]=-1      )					->    List[str]:
												a__             =     time()
												self.dfs(__snake_case			,__snake_case      )
												a__             =     time()
												return end - begin



					def  lowerCamelCase__(      self   :Union[str, Any]			,__snake_case   :int=-2      )					->    str:
												a__             =     time()
												self.bfs(__snake_case      )
												a__             =     time()
												return end - begin








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)




