



from manim import *

class       snake_case__(UpperCAmelCase__			):

					"""simple docstring"""






					def  snake_case     (							self					:	Union[str, Any]     ):
									lowercase__     :    Union[str, Any]													=     Rectangle(height=0.5      ,   width=0.5     )
									lowercase__     :    List[Any]													=     Rectangle(height=0.25      ,   width=0.25     )
									lowercase__     :    List[Any]													=     Rectangle(height=0.46      ,   width=0.46     ).set_stroke(width=0     )

									lowercase__     :    Optional[Any]													=     [mem.copy() for i in range(6     )]
									lowercase__     :    List[str]													=     [mem.copy() for i in range(6     )]
									lowercase__     :    List[str]													=     VGroup(*lowercase_     ).arrange(lowercase_      ,   buff=0     )
									lowercase__     :    Dict													=     VGroup(*lowercase_     ).arrange(lowercase_      ,   buff=0     )
									lowercase__     :    Optional[Any]													=     VGroup(lowercase_      ,   lowercase_     ).arrange(lowercase_      ,   buff=0     )
									lowercase__     :    List[Any]													=     Text("CPU"      ,   font_size=24     )
									lowercase__     :    Tuple													=     Group(lowercase_      ,   lowercase_     ).arrange(lowercase_      ,   buff=0.5      ,   aligned_edge=lowercase_     )
									cpu.move_to([-2.5, -0.5, 0]     )
									self.add(lowercase_     )

									lowercase__     :    Any													=     [mem.copy() for i in range(4     )]
									lowercase__     :    Union[str, Any]													=     VGroup(*lowercase_     ).arrange(lowercase_      ,   buff=0     )
									lowercase__     :    List[str]													=     Text("GPU"      ,   font_size=24     )
									lowercase__     :    Union[str, Any]													=     Group(lowercase_      ,   lowercase_     ).arrange(lowercase_      ,   buff=0.5      ,   aligned_edge=lowercase_     )
									gpu.move_to([-1, -1, 0]     )
									self.add(lowercase_     )

									lowercase__     :    Optional[int]													=     [mem.copy() for i in range(6     )]
									lowercase__     :    int													=     VGroup(*lowercase_     ).arrange(lowercase_      ,   buff=0     )

									lowercase__     :    List[Any]													=     Text("Model"      ,   font_size=24     )
									lowercase__     :    Union[str, Any]													=     Group(lowercase_      ,   lowercase_     ).arrange(lowercase_      ,   buff=0.5      ,   aligned_edge=lowercase_     )
									model.move_to([3, -1.0, 0]     )
									self.add(lowercase_     )

									lowercase__     :    Tuple													=     []
									lowercase__     :    int													=     []
									lowercase__     :    Any													=     []

									for i, rect in enumerate(lowercase_     ):
													rect.set_stroke(lowercase_     )

													lowercase__     :    Optional[int]													=     Rectangle(height=0.46 / 4      ,   width=0.46 / 3     ).set_stroke(width=0.0     ).set_fill(lowercase_      ,   opacity=0.7     )

													if i == 0:
																	cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT     )      ,   buff=0.02      ,   direction=lowercase_     )
																	cpu_target.set_x(cpu_target.get_x() + 0.1     )
													elif i == 3:
																	cpu_target.next_to(model_cpu_arr[0]      ,   direction=lowercase_      ,   buff=0.0     )
													else:
																	cpu_target.next_to(model_cpu_arr[i - 1]      ,   direction=lowercase_      ,   buff=0.0     )
													self.add(lowercase_     )
													model_cpu_arr.append(lowercase_     )

									self.add(*lowercase_      ,   *lowercase_      ,   *lowercase_     )

									lowercase__     :    Any													=     [mem.copy() for i in range(6     )]
									lowercase__     :    Any													=     VGroup(*lowercase_     ).arrange(lowercase_      ,   buff=0     )

									lowercase__     :    Union[str, Any]													=     Text("Loaded Checkpoint"      ,   font_size=24     )
									lowercase__     :    List[Any]													=     Group(lowercase_      ,   lowercase_     ).arrange(lowercase_      ,   buff=0.5      ,   aligned_edge=lowercase_     )
									checkpoint.move_to([3, 0.5, 0]     )

									self.add(lowercase_     )

									lowercase__     :    Dict													=     []
									lowercase__     :    Dict													=     []

									for i, rect in enumerate(lowercase_     ):
													lowercase__     :    Any													=     fill.copy().set_fill(lowercase_      ,   opacity=0.7     )
													target.move_to(lowercase_     )
													ckpt_arr.append(lowercase_     )

													lowercase__     :    Any													=     target.copy()
													if i < 5:
																	cpu_target.move_to(cpu_left_col_base[i + 1]     )
													else:
																	cpu_target.move_to(cpu_right_col_base[i - 5]     )
													ckpt_cpu_arr.append(lowercase_     )
									self.add(*lowercase_      ,   *lowercase_     )

									lowercase__     :    Union[str, Any]													=     Square(side_length=2.2     )
									key.move_to([-5, 2, 0]     )

									lowercase__     :    int													=     MarkupText(
									    f"""<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model"""      ,   font_size=18      ,   )

									key_text.move_to([-5, 2.4, 0]     )

									self.add(lowercase_      ,   lowercase_     )

									lowercase__     :    List[Any]													=     MarkupText(
									    f"""<span fgcolor=\'{BLUE}\'>●</span> Checkpoint"""      ,   font_size=18      ,   )

									blue_text.next_to(lowercase_      ,   DOWN * 2.4      ,   aligned_edge=key_text.get_left()     )
									self.add(lowercase_     )

									lowercase__     :    List[Any]													=     MarkupText(
									    f"""Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device."""      ,   font_size=24      ,   )
									step_a.move_to([2, 2, 0]     )

									lowercase__     :    List[str]													=     [meta_mem.copy() for i in range(6     )]
									lowercase__     :    Any													=     [meta_mem.copy() for i in range(6     )]
									lowercase__     :    Any													=     VGroup(*lowercase_     ).arrange(lowercase_      ,   buff=0     )
									lowercase__     :    Optional[Any]													=     VGroup(*lowercase_     ).arrange(lowercase_      ,   buff=0     )
									lowercase__     :    List[Any]													=     VGroup(lowercase_      ,   lowercase_     ).arrange(lowercase_      ,   buff=0     )
									lowercase__     :    Dict													=     Text("Disk"      ,   font_size=24     )
									lowercase__     :    str													=     Group(lowercase_      ,   lowercase_     ).arrange(lowercase_      ,   buff=0.5      ,   aligned_edge=lowercase_     )
									disk.move_to([-4.0, -1.25, 0]     )
									self.play(Write(lowercase_      ,   run_time=3     )      ,   Write(lowercase_      ,   run_time=1     )      ,   Create(lowercase_      ,   run_time=1     )     )

									lowercase__     :    int													=     []
									for i, rect in enumerate(lowercase_     ):
													lowercase__     :    List[Any]													=     rect.copy()
													target.generate_target()
													target.target.move_to(disk_left_col_base[i]     ).scale(0.5     )
													animations.append(MoveToTarget(lowercase_      ,   run_time=1.5     )     )
									self.play(*lowercase_     )

									self.play(FadeOut(lowercase_     )     )

									lowercase__     :    Any													=     MarkupText(f"""Then, the checkpoint is removed from memory\nthrough garbage collection."""      ,   font_size=24     )
									step_a.move_to([2, 2, 0]     )

									self.play(Write(lowercase_      ,   run_time=3     )     )

									self.play(
									    FadeOut(lowercase_      ,   lowercase_      ,   *lowercase_      ,   *lowercase_     )      ,   )

									self.wait()












"""simple docstring"""






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 					_A			(__a    ,				__a    ,				__a							) ->       Dict:
    """simple docstring"""






    if gpta_config_file == "":
        SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		GPTaConfig()
    else:
        SCREAMING_SNAKE_CASE_      :  Tuple    						=		GPTaConfig.from_json_file(__a							)
    SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		GPTaModel(__a							)

    # Load weights from numpy
    load_tf_weights_in_gpta(__a    ,				__a    ,				__a							)

    # Save pytorch-model
    SCREAMING_SNAKE_CASE_      :  List[str]    						=		pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
    SCREAMING_SNAKE_CASE_      :  List[Any]    						=		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__":
  UpperCAmelCase_   : str   			= 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."""
      ),
  )
  UpperCAmelCase_   : Union[str, Any]   			= parser.parse_args()
  convert_gpta_checkpoint_to_pytorch(args.gpta_checkpoint_path, args.gpta_config_file, args.pytorch_dump_folder_path)


