'''simple docstring'''






import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp






def    __UpperCAmelCase			(  ):
   _UpperCAmelCase							:	List[str]							=   ArgumentParser(
       description=(
           "PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes"
       )							)

   # Optional arguments for the launch helper
   parser.add_argument("--num_cores",					type=a_,					default=1,					help="Number of TPU cores to use (1 or 8)."							)

   # positional
   parser.add_argument(
       "training_script",					type=a_,					help=(
           "The full path to the single TPU training "
           "program/script to be launched in parallel, "
           "followed by all the arguments for the "
           "training script"
       ),					)

   # rest from the training program
   parser.add_argument("training_script_args",					nargs=a_							)

   return parser.parse_args()






def    __UpperCAmelCase			(  ):
   _UpperCAmelCase							:	str							=   parse_args()

   # Import training_script as a module.
   _UpperCAmelCase							:	Tuple							=   Path(args.training_script							)
   sys.path.append(str(script_fpath.parent.resolve()							)							)
   _UpperCAmelCase							:	Dict							=   script_fpath.stem
   _UpperCAmelCase							:	Optional[Any]							=   importlib.import_module(a_							)

   # Patch sys.argv
   _UpperCAmelCase							:	Optional[int]							=   [args.training_script] + args.training_script_args + ['''--tpu_num_cores''', str(args.num_cores							)]

   xmp.spawn(mod._mp_fn,					args=(),					nprocs=args.num_cores							)


if __name__ == "__main__":
     main()
import argparse

import torch

from ...utils import logging
from . import AlbertConfig, AlbertForPreTraining, load_tf_weights_in_albert


logging.set_verbosity_info()



def lowerCamelCase  (   SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE	):
    '''simple docstring'''







    __UpperCamelCase     :List[Any]			  =		AlbertConfig.from_json_file(SCREAMING_SNAKE_CASE	)
    print(f"""Building PyTorch model from configuration: {config}"""	)
    __UpperCamelCase     :List[str]			  =		AlbertForPreTraining(SCREAMING_SNAKE_CASE	)

    # Load weights from tf checkpoint
    load_tf_weights_in_albert(SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE  ,			SCREAMING_SNAKE_CASE	)

    # Save pytorch-model
    print(f"""Save PyTorch model to {pytorch_dump_path}"""	)
    torch.save(model.state_dict()  ,			SCREAMING_SNAKE_CASE	)


if __name__ == "__main__":
    __lowercase							 =					argparse.ArgumentParser()
    # Required parameters
    parser.add_argument(
        '''--tf_checkpoint_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
    )
    parser.add_argument(
        '''--albert_config_file''',
        default=None,
        type=str,
        required=True,
        help=(
            '''The config json file corresponding to the pre-trained ALBERT model. \n'''
            '''This specifies the model architecture.'''
        ),
    )
    parser.add_argument(
        '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
    )
    __lowercase							 =					parser.parse_args()
    convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.albert_config_file, args.pytorch_dump_path)





