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

import torch_xla.distributed.xla_multiprocessing as xmp


def     UpperCamelCase      (					):
       snake_case :     Tuple           =   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     UpperCamelCase      (					):
       snake_case :     Dict           =   parse_args()

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

       # Patch sys.argv
       snake_case :     Union[str, Any]           =   [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 unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils






class 						UpperCAmelCase	(		unittest.TestCase				):



   @patch("diffusers.utils.hub_utils.get_full_repo_name"				)
   def        _SCREAMING_SNAKE_CASE     (self	:      Any					,		snake_case__	:      Mock				)	->			None:


          '''simple docstring'''


          snake_case :     str           =   "full_repo_name"
          with TemporaryDirectory() as tmpdir:
                 # Dummy args values
                 snake_case :     List[str]           =   Mock()
                 snake_case :     List[str]           =   tmpdir
                 snake_case :     Optional[int]           =   0
                 snake_case :     int           =   "hub_token"
                 snake_case :     Union[str, Any]           =   "dataset_name"
                 snake_case :     Tuple           =   0.01
                 snake_case :     int           =   10_00_00
                 snake_case :     Optional[Any]           =   1_00_00
                 snake_case :     Optional[Any]           =   0.01
                 snake_case :     Dict           =   0.02
                 snake_case :     List[Any]           =   0.03
                 snake_case :     str           =   0.0005
                 snake_case :     List[str]           =   0.000001
                 snake_case :     Tuple           =   1
                 snake_case :     Optional[int]           =   10
                 snake_case :     List[str]           =   0.001
                 snake_case :     List[Any]           =   0.1
                 snake_case :     List[str]           =   0.2
                 snake_case :     Tuple           =   True

                 # Model card mush be rendered and saved
                 diffusers.utils.hub_utils.create_model_card(snake_case__					,		model_name="model_name"				)
                 self.assertTrue((Path(snake_case__				) / "README.md").is_file()				)





