




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

import torch_xla.distributed.xla_multiprocessing as xmp




def 							_UpperCAmelCase  ():
				'''simple docstring'''
				_lowerCAmelCase    :    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=UpperCamelCase_      ,    default=1      ,    help="""Number of TPU cores to use (1 or 8)."""       )

				# positional
				parser.add_argument(
				    """training_script"""      ,    type=UpperCamelCase_      ,    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=UpperCamelCase_       )

				return parser.parse_args()




def 							_UpperCAmelCase  ():
				'''simple docstring'''
				_lowerCAmelCase    :    Any										=      parse_args()

				# Import training_script as a module.
				_lowerCAmelCase    :    int										=      Path(args.training_script       )
				sys.path.append(str(script_fpath.parent.resolve()       )       )
				_lowerCAmelCase    :    List[Any]										=      script_fpath.stem
				_lowerCAmelCase    :    str										=      importlib.import_module(UpperCamelCase_       )

				# Patch sys.argv
				_lowerCAmelCase    :    str										=      [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()







def 							_UpperCAmelCase  (UpperCamelCase_ : str      ,    UpperCamelCase_ : bool = False       ):
				'''simple docstring'''

				if not isinstance(UpperCamelCase_      ,    UpperCamelCase_       ):
								_lowerCAmelCase    :    Tuple										=      F"Expected string as input, found {type(UpperCamelCase_       )}"
								raise ValueError(UpperCamelCase_       )
				if not isinstance(UpperCamelCase_      ,    UpperCamelCase_       ):
								_lowerCAmelCase    :    Optional[Any]										=      F"Expected boolean as use_pascal parameter, found {type(UpperCamelCase_       )}"
								raise ValueError(UpperCamelCase_       )

				_lowerCAmelCase    :    Any										=      input_str.split("""_"""       )

				_lowerCAmelCase    :    str										=      0 if use_pascal else 1

				_lowerCAmelCase    :    Any										=      words[start_index:]

				_lowerCAmelCase    :    List[str]										=      [word[0].upper() + word[1:] for word in words_to_capitalize]

				_lowerCAmelCase    :    Any										=      """""" if use_pascal else words[0]

				return "".join([initial_word, *capitalized_words]       )


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

	testmod()

