





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

import torch_xla.distributed.xla_multiprocessing as xmp



def 		A_    (					)						->			Optional[Any]:
 UpperCamelCase     : Optional[int]	     =       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=_lowerCAmelCase							,       default=1							,       help="Number of TPU cores to use (1 or 8)."					)

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

 return parser.parse_args()



def 		A_    (					)						->			Tuple:
 UpperCamelCase     : Union[str, Any]	     =       parse_args()

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

 # Patch sys.argv
 UpperCamelCase     : Tuple	     =       [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 sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

__lowerCamelCase	:					Optional[int]			  =					"""python tqdm regex requests packaging filelock numpy tokenizers""".split()
if sys.version_info < (3, 7):
    pkgs_to_check_at_runtime.append("""dataclasses""")
if sys.version_info < (3, 8):
    pkgs_to_check_at_runtime.append("""importlib_metadata""")

for pkg in pkgs_to_check_at_runtime:
    if pkg in deps:
        if pkg == "tokenizers":
            # must be loaded here, or else tqdm check may fail
            from .utils import is_tokenizers_available

            if not is_tokenizers_available():
                continue  # not required, check version only if installed

        require_version_core(deps[pkg])
    else:
        raise ValueError(f"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")



def 		A_    (					_lowerCAmelCase							,       _lowerCAmelCase=None					)						->			Optional[Any]:
 require_version(deps[pkg]							,       _lowerCAmelCase					)
