import argparse

import torch

from transformers import ImageGPTConfig, ImageGPTForCausalLM, load_tf_weights_in_imagegpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()
def 							lowerCAmelCase(	__lowerCamelCase      ,				__lowerCamelCase      ,				__lowerCamelCase						):
					# Construct configuration depending on size
					__a							=   {'small': (512, 8, 24), 'medium': (1024, 8, 36), 'large': (1536, 16, 48)}
					__a							=   MODELS[model_size]  # set model hyperparameters
					__a							=   ImageGPTConfig(n_embd=__lowerCamelCase      ,				n_layer=__lowerCamelCase      ,				n_head=__lowerCamelCase						)
					__a							=   ImageGPTForCausalLM(__lowerCamelCase						)

					# Load weights from numpy
					load_tf_weights_in_imagegpt(__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__":
	lowerCamelCase_				:		Tuple       						=       argparse.ArgumentParser()
	# Required parameters
	parser.add_argument(
	    """--imagegpt_checkpoint_path""",
	    default=None,
	    type=str,
	    required=True,
	    help="""Path to the TensorFlow checkpoint path.""",
	)
	parser.add_argument(
	    """--model_size""",
	    default=None,
	    type=str,
	    required=True,
	    help="""Size of the model (can be either 'small', 'medium' or 'large').""",
	)
	parser.add_argument(
	    """--pytorch_dump_folder_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
	)
	lowerCamelCase_				:		Optional[int]       						=       parser.parse_args()
	convert_imagegpt_checkpoint_to_pytorch(
	    args.imagegpt_checkpoint_path, args.model_size, args.pytorch_dump_folder_path
	)











def 			lowerCamelCase_		(					lowerCAmelCase:		str			,							lowerCAmelCase:		str )->						int:
  # The longer word should come first
  if len(lowerCAmelCase ) < len(lowerCAmelCase ):
    return levenshtein_distance(lowerCAmelCase			,							lowerCAmelCase )

  if len(lowerCAmelCase ) == 0:
    return len(lowerCAmelCase )

  _snake_case      : Dict														=		list(range(len(lowerCAmelCase ) + 1 ) )

  for i, ca in enumerate(lowerCAmelCase ):
    _snake_case      : Optional[int]														=		[i + 1]

    for j, ca in enumerate(lowerCAmelCase ):
      # Calculate insertions, deletions and substitutions
      _snake_case      : Optional[Any]														=		previous_row[j + 1] + 1
      _snake_case      : Optional[int]														=		current_row[j] + 1
      _snake_case      : Union[str, Any]														=		previous_row[j] + (ca != ca)

      # Get the minimum to append to the current row
      current_row.append(min(lowerCAmelCase			,							lowerCAmelCase			,							lowerCAmelCase ) )

    # Store the previous row
    _snake_case      : str														=		current_row

  # Returns the last element (distance)
  return previous_row[-1]


if __name__ == "__main__":
      lowerCAmelCase_        =			input("""Enter the first word:\n""").strip()
      lowerCAmelCase_        =			input("""Enter the second word:\n""").strip()

      lowerCAmelCase_        =			levenshtein_distance(first_word, second_word)
      print(F"""Levenshtein distance between {first_word} and {second_word} is {result}""")




