
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    _lowerCAmelCase    (     lowerCamelCase__							:							List[Any],						lowerCamelCase__							:							List[Any],						lowerCamelCase__							:							Tuple				)  ->    Optional[Any]:







  if openai_config_file == "":
    _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = OpenAIGPTConfig()
  else:
    _SCREAMING_SNAKE_CASE   :				Tuple							    = OpenAIGPTConfig.from_json_file(lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE   :				Optional[int]							    = OpenAIGPTModel(lowerCamelCase__				)

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

  # Save pytorch-model
  _SCREAMING_SNAKE_CASE   :				List[Any]							    = pytorch_dump_folder_path + "/" + WEIGHTS_NAME
  _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = 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__":
      lowercase_       :						Optional[int]     					=	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.'''
          ),
      )
      lowercase_       :						Optional[Any]     					=	parser.parse_args()
      convert_openai_checkpoint_to_pytorch(
          args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
      )





"""simple docstring"""
from __future__ import annotations

import time
from collections.abc import Sequence
from random import randint

from matplotlib import pyplot as plt





def    _lowerCAmelCase    (     lowerCamelCase__							:							Sequence[float],						lowerCamelCase__							:							int,						lowerCamelCase__							:							int				)  ->    tuple[int | None, int | None, float]:
  if not arr:
    return None, None, 0
  if low == high:
    return low, high, arr[low]

  _SCREAMING_SNAKE_CASE   :				Any							    = (low + high) // 2
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Optional[int]							    = max_subarray(lowerCamelCase__,						lowerCamelCase__,						lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				List[str]							    = max_subarray(lowerCamelCase__,						mid + 1,						lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				str							    = max_cross_sum(lowerCamelCase__,						lowerCamelCase__,						lowerCamelCase__,						lowerCamelCase__				)
  if left_sum >= right_sum and left_sum >= cross_sum:
    return left_low, left_high, left_sum
  elif right_sum >= left_sum and right_sum >= cross_sum:
    return right_low, right_high, right_sum
  return cross_left, cross_right, cross_sum





def    _lowerCAmelCase    (     lowerCamelCase__							:							Sequence[float],						lowerCamelCase__							:							int,						lowerCamelCase__							:							int,						lowerCamelCase__							:							int				)  ->    tuple[int, int, float]:
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				List[Any]							    = float("-inf"				), -1
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Dict							    = float("-inf"				), -1

  _SCREAMING_SNAKE_CASE   :				int | float							    = 0
  for i in range(lowerCamelCase__,						low - 1,						-1				):
    summ += arr[i]
    if summ > left_sum:
      _SCREAMING_SNAKE_CASE   :				int							    = summ
      _SCREAMING_SNAKE_CASE   :				Tuple							    = i

  _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = 0
  for i in range(mid + 1,						high + 1				):
    summ += arr[i]
    if summ > right_sum:
      _SCREAMING_SNAKE_CASE   :				int							    = summ
      _SCREAMING_SNAKE_CASE   :				Any							    = i

  return max_left, max_right, (left_sum + right_sum)





def    _lowerCAmelCase    (     lowerCamelCase__							:							int				)  ->    float:
  _SCREAMING_SNAKE_CASE   :				Any							    = [randint(1,						lowerCamelCase__				) for _ in range(lowerCamelCase__				)]
  _SCREAMING_SNAKE_CASE   :				int							    = time.time()
  max_subarray(lowerCamelCase__,						0,						input_size - 1				)
  _SCREAMING_SNAKE_CASE   :				List[str]							    = time.time()
  return end - start





def    _lowerCAmelCase    (     )  ->    None:
  _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = [1_0, 1_0_0, 1_0_0_0, 1_0_0_0_0, 5_0_0_0_0, 1_0_0_0_0_0, 2_0_0_0_0_0, 3_0_0_0_0_0, 4_0_0_0_0_0, 5_0_0_0_0_0]
  _SCREAMING_SNAKE_CASE   :				int							    = [time_max_subarray(lowerCamelCase__				) for input_size in input_sizes]
  print("No of Inputs\t\tTime Taken"				)
  for input_size, runtime in zip(lowerCamelCase__,						lowerCamelCase__				):
    print(lowerCamelCase__,						"\t\t",						lowerCamelCase__				)
  plt.plot(lowerCamelCase__,						lowerCamelCase__				)
  plt.xlabel("Number of Inputs"				)
  plt.ylabel("Time taken in seconds"				)
  plt.show()


if __name__ == "__main__":
      from doctest import testmod

      testmod()



