


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






class      UpperCamelCase					:


   '''simple docstring'''







   def __init__(     self		):
        lowercase_       :Optional[int]     =       {}
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_=1		):

        if self.graph.get(UpperCamelCase_		):
             if self.graph[u].count([w, v]		) == 0:
                  self.graph[u].append([w, v]		)
        else:
             lowercase_       :List[Any]     =       [[w, v]]
        if not self.graph.get(UpperCamelCase_		):
             lowercase_       :str     =       []
   def 		UpperCamelCase  (     self		):
        return list(self.graph		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_		):

        if self.graph.get(UpperCamelCase_		):
             for _ in self.graph[u]:
                  if _[1] == v:
                       self.graph[u].remove(UpperCamelCase_		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2   ,							UpperCamelCase_=-1		):

        if s == d:
             return []
        lowercase_       :List[str]     =       []
        lowercase_       :Optional[int]     =       []
        if s == -2:
             lowercase_       :int     =       list(self.graph		)[0]
        stack.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        lowercase_       :Optional[Any]     =       s

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

            # check if all the children are visited
             if s == ss:
                  stack.pop()
                  if len(UpperCamelCase_		) != 0:
                       lowercase_       :Any     =       stack[len(UpperCamelCase_		) - 1]
             else:
                  lowercase_       :Optional[int]     =       ss

             # check if se have reached the starting point
             if len(UpperCamelCase_		) == 0:
                  return visited
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-1		):

        if c == -1:
             lowercase_       :Optional[int]     =       floor(random() * 1_0000		) + 10
        for i in range(UpperCamelCase_		):
             # every vertex has max 100 edges
             for _ in range(floor(random() * 102		) + 1		):
                  lowercase_       :List[Any]     =       floor(random() * c		) + 1
                  if n != i:
                       self.add_pair(UpperCamelCase_   ,							UpperCamelCase_   ,							1		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2		):
        lowercase_       :List[str]     =       deque()
        lowercase_       :str     =       []
        if s == -2:
             lowercase_       :Tuple     =       list(self.graph		)[0]
        d.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        while d:
             lowercase_       :Union[str, Any]     =       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 		UpperCamelCase  (     self   ,							UpperCamelCase_		):
        lowercase_       :Tuple     =       0
        for x in self.graph:
             for y in self.graph[x]:
                  if y[1] == u:
                       count += 1
        return count
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_		):
        return len(self.graph[u]		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2		):
        lowercase_       :List[Any]     =       []
        lowercase_       :Optional[Any]     =       []
        if s == -2:
             lowercase_       :Dict     =       list(self.graph		)[0]
        stack.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        lowercase_       :Optional[Any]     =       s
        lowercase_       :List[Any]     =       []

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

            # check if all the children are visited
             if s == ss:
                  sorted_nodes.append(stack.pop()		)
                  if len(UpperCamelCase_		) != 0:
                       lowercase_       :Union[str, Any]     =       stack[len(UpperCamelCase_		) - 1]
             else:
                  lowercase_       :Union[str, Any]     =       ss

             # check if se have reached the starting point
             if len(UpperCamelCase_		) == 0:
                  return sorted_nodes
   def 		UpperCamelCase  (     self		):
        lowercase_       :List[Any]     =       []
        lowercase_       :str     =       []
        lowercase_       :Optional[int]     =       list(self.graph		)[0]
        stack.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        lowercase_       :int     =       -2
        lowercase_       :str     =       []
        lowercase_       :Any     =       s
        lowercase_       :List[str]     =       False
        lowercase_       :List[str]     =       set()

        while True:
             # check if there is any non isolated nodes
             if len(self.graph[s]		) != 0:
                  lowercase_       :Optional[Any]     =       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
                       ):
                            lowercase_       :Any     =       len(UpperCamelCase_		) - 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]		)
                            lowercase_       :Optional[Any]     =       node[1]
                            break

            # check if all the children are visited
             if s == ss:
                  stack.pop()
                  lowercase_       :Union[str, Any]     =       True
                  if len(UpperCamelCase_		) != 0:
                       lowercase_       :Optional[int]     =       stack[len(UpperCamelCase_		) - 1]
             else:
                  lowercase_       :Optional[Any]     =       False
                  indirect_parents.append(UpperCamelCase_		)
                  lowercase_       :List[Any]     =       s
                  lowercase_       :Union[str, Any]     =       ss

             # check if se have reached the starting point
             if len(UpperCamelCase_		) == 0:
                  return list(UpperCamelCase_		)
   def 		UpperCamelCase  (     self		):
        lowercase_       :Any     =       []
        lowercase_       :Optional[Any]     =       []
        lowercase_       :Tuple     =       list(self.graph		)[0]
        stack.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        lowercase_       :List[Any]     =       -2
        lowercase_       :str     =       []
        lowercase_       :List[Any]     =       s
        lowercase_       :str     =       False
        lowercase_       :str     =       set()

        while True:
             # check if there is any non isolated nodes
             if len(self.graph[s]		) != 0:
                  lowercase_       :List[str]     =       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
                       ):
                            lowercase_       :Union[str, Any]     =       len(UpperCamelCase_		) - 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]		)
                            lowercase_       :Dict     =       node[1]
                            break

            # check if all the children are visited
             if s == ss:
                  stack.pop()
                  lowercase_       :Tuple     =       True
                  if len(UpperCamelCase_		) != 0:
                       lowercase_       :int     =       stack[len(UpperCamelCase_		) - 1]
             else:
                  lowercase_       :str     =       False
                  indirect_parents.append(UpperCamelCase_		)
                  lowercase_       :List[str]     =       s
                  lowercase_       :Optional[int]     =       ss

             # check if se have reached the starting point
             if len(UpperCamelCase_		) == 0:
                  return False
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2   ,							UpperCamelCase_=-1		):
        lowercase_       :Tuple     =       time()
        self.dfs(UpperCamelCase_   ,							UpperCamelCase_		)
        lowercase_       :List[Any]     =       time()
        return end - begin




   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2		):
        lowercase_       :List[Any]     =       time()
        self.bfs(UpperCamelCase_		)
        lowercase_       :int     =       time()
        return end - begin






class      UpperCamelCase					:


   '''simple docstring'''







   def __init__(     self		):
        lowercase_       :List[Any]     =       {}
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_=1		):

        if self.graph.get(UpperCamelCase_		):
             # 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
             lowercase_       :Any     =       [[w, v]]
        # add the other way
        if self.graph.get(UpperCamelCase_		):
             # 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
             lowercase_       :Optional[Any]     =       [[w, u]]
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_		):

        if self.graph.get(UpperCamelCase_		):
             for _ in self.graph[u]:
                  if _[1] == v:
                       self.graph[u].remove(UpperCamelCase_		)
        # the other way round
        if self.graph.get(UpperCamelCase_		):
             for _ in self.graph[v]:
                  if _[1] == u:
                       self.graph[v].remove(UpperCamelCase_		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2   ,							UpperCamelCase_=-1		):

        if s == d:
             return []
        lowercase_       :Dict     =       []
        lowercase_       :Union[str, Any]     =       []
        if s == -2:
             lowercase_       :Optional[int]     =       list(self.graph		)[0]
        stack.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        lowercase_       :Dict     =       s

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

            # check if all the children are visited
             if s == ss:
                  stack.pop()
                  if len(UpperCamelCase_		) != 0:
                       lowercase_       :Union[str, Any]     =       stack[len(UpperCamelCase_		) - 1]
             else:
                  lowercase_       :Any     =       ss

             # check if se have reached the starting point
             if len(UpperCamelCase_		) == 0:
                  return visited
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-1		):

        if c == -1:
             lowercase_       :List[Any]     =       floor(random() * 1_0000		) + 10
        for i in range(UpperCamelCase_		):
             # every vertex has max 100 edges
             for _ in range(floor(random() * 102		) + 1		):
                  lowercase_       :Optional[int]     =       floor(random() * c		) + 1
                  if n != i:
                       self.add_pair(UpperCamelCase_   ,							UpperCamelCase_   ,							1		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2		):
        lowercase_       :Tuple     =       deque()
        lowercase_       :Any     =       []
        if s == -2:
             lowercase_       :int     =       list(self.graph		)[0]
        d.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        while d:
             lowercase_       :List[Any]     =       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 		UpperCamelCase  (     self   ,							UpperCamelCase_		):
        return len(self.graph[u]		)
   def 		UpperCamelCase  (     self		):
        lowercase_       :Optional[int]     =       []
        lowercase_       :Optional[Any]     =       []
        lowercase_       :List[Any]     =       list(self.graph		)[0]
        stack.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        lowercase_       :Dict     =       -2
        lowercase_       :List[Any]     =       []
        lowercase_       :Any     =       s
        lowercase_       :List[str]     =       False
        lowercase_       :List[str]     =       set()

        while True:
             # check if there is any non isolated nodes
             if len(self.graph[s]		) != 0:
                  lowercase_       :List[Any]     =       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
                       ):
                            lowercase_       :Optional[Any]     =       len(UpperCamelCase_		) - 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]		)
                            lowercase_       :Any     =       node[1]
                            break

            # check if all the children are visited
             if s == ss:
                  stack.pop()
                  lowercase_       :Optional[int]     =       True
                  if len(UpperCamelCase_		) != 0:
                       lowercase_       :Any     =       stack[len(UpperCamelCase_		) - 1]
             else:
                  lowercase_       :List[Any]     =       False
                  indirect_parents.append(UpperCamelCase_		)
                  lowercase_       :List[str]     =       s
                  lowercase_       :Any     =       ss

             # check if se have reached the starting point
             if len(UpperCamelCase_		) == 0:
                  return list(UpperCamelCase_		)
   def 		UpperCamelCase  (     self		):
        lowercase_       :Dict     =       []
        lowercase_       :str     =       []
        lowercase_       :Optional[int]     =       list(self.graph		)[0]
        stack.append(UpperCamelCase_		)
        visited.append(UpperCamelCase_		)
        lowercase_       :int     =       -2
        lowercase_       :int     =       []
        lowercase_       :List[Any]     =       s
        lowercase_       :Union[str, Any]     =       False
        lowercase_       :Tuple     =       set()

        while True:
             # check if there is any non isolated nodes
             if len(self.graph[s]		) != 0:
                  lowercase_       :List[str]     =       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
                       ):
                            lowercase_       :Union[str, Any]     =       len(UpperCamelCase_		) - 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]		)
                            lowercase_       :Tuple     =       node[1]
                            break

            # check if all the children are visited
             if s == ss:
                  stack.pop()
                  lowercase_       :int     =       True
                  if len(UpperCamelCase_		) != 0:
                       lowercase_       :Dict     =       stack[len(UpperCamelCase_		) - 1]
             else:
                  lowercase_       :Optional[Any]     =       False
                  indirect_parents.append(UpperCamelCase_		)
                  lowercase_       :Dict     =       s
                  lowercase_       :Tuple     =       ss

             # check if se have reached the starting point
             if len(UpperCamelCase_		) == 0:
                  return False
   def 		UpperCamelCase  (     self		):
        return list(self.graph		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2   ,							UpperCamelCase_=-1		):
        lowercase_       :Union[str, Any]     =       time()
        self.dfs(UpperCamelCase_   ,							UpperCamelCase_		)
        lowercase_       :Any     =       time()
        return end - begin




   def 		UpperCamelCase  (     self   ,							UpperCamelCase_=-2		):
        lowercase_       :List[str]     =       time()
        self.bfs(UpperCamelCase_		)
        lowercase_       :List[str]     =       time()
        return end - begin





import argparse

import torch

from transformers import OpenAIGPTConfig, OpenAIGPTModel, load_tf_weights_in_openai_gpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()




def     UpperCamelCase    (      _a       ,		_a       ,		_a		)					->							List[str]:
     '''simple docstring'''





     if openai_config_file == "":
          lowercase_       :str     =       OpenAIGPTConfig()
     else:
          lowercase_       :int     =       OpenAIGPTConfig.from_json_file(_a		)
     lowercase_       :int     =       OpenAIGPTModel(_a		)

     # Load weights from numpy
     load_tf_weights_in_openai_gpt(_a       ,		_a       ,		_a		)

     # Save pytorch-model
     lowercase_       :Optional[int]     =       pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
     lowercase_       :List[str]     =       pytorch_dump_folder_path + '''/''' + CONFIG_NAME
     print(f"Save PyTorch model to {pytorch_weights_dump_path}"		)
     torch.save(model.state_dict()       ,		_a		)
     print(f"Save configuration file to {pytorch_config_dump_path}"		)
     with open(_a       ,		'''w'''       ,		encoding='''utf-8'''		) as f:
          f.write(config.to_json_string()		)


if __name__ == "__main__":
   SCREAMING_SNAKE_CASE       :		List[str]         =				argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       "--openai_checkpoint_folder_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(
       "--openai_config_file",
       default="",
       type=str,
       help=(
           "An optional config json file corresponding to the pre-trained OpenAI model. \n"
           "This specifies the model architecture."
       ),
   )
   SCREAMING_SNAKE_CASE       :		Optional[Any]         =				parser.parse_args()
   convert_openai_checkpoint_to_pytorch(
       args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
   )

