




"""simple docstring"""


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__ (snake_case__							:      Union[str, Any]	,     snake_case__							:      Any	,     snake_case__							:      Optional[Any]					):
  """simple docstring"""

  if openai_config_file == "":
    _snake_case							:	int			=						OpenAIGPTConfig()
  else:
    _snake_case							:	str			=						OpenAIGPTConfig.from_json_file(snake_case__					)
  _snake_case							:	int			=						OpenAIGPTModel(snake_case__					)

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

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


if __name__ == "__main__":
     A_      			=       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.'''
         ),
     )
     A_      			=       parser.parse_args()
     convert_openai_checkpoint_to_pytorch(
         args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
     )








"""simple docstring"""


def       UpperCAmelCase__ (snake_case__							:      int					):
  """simple docstring"""

  if not isinstance(snake_case__	,     snake_case__					) or number < 0:
    raise ValueError("""Input must be a non-negative integer"""					)

  _snake_case							:	Dict			=						0
  while number:
    # This way we arrive at next set bit (next 1) instead of looping
    # through each bit and checking for 1s hence the
    # loop won't run 32 times it will only run the number of `1` times
    number &= number - 1
    count += 1
  return count


if __name__ == "__main__":
     import doctest

     doctest.testmod()


