
"""simple docstring"""







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

import torch_xla.distributed.xla_multiprocessing as xmp




def       A_      (       )  ->				List[Any]:


     """simple docstring"""







     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=lowercase    ,			default=1    ,			help="""Number of TPU cores to use (1 or 8)."""   )

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

     return parser.parse_args()




def       A_      (       )  ->				List[Any]:


     """simple docstring"""







     UpperCAmelCase_    :     Union[str, Any]            =	parse_args()

     # Import training_script as a module.
     UpperCAmelCase_    :     Dict            =	Path(args.training_script   )
     sys.path.append(str(script_fpath.parent.resolve()   )   )
     UpperCAmelCase_    :     Any            =	script_fpath.stem
     UpperCAmelCase_    :     str            =	importlib.import_module(lowercase   )

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



"""simple docstring"""







class 		UpperCAmelCase_						:
 """simple docstring"""




 def __init__(			self							:			Optional[Any]  , a_							:			int			)->       str:



      """simple docstring"""

      UpperCAmelCase_    :     Any            =	n
      UpperCAmelCase_    :     str            =	[None] * self.n
      UpperCAmelCase_    :     List[Any]            =	0  # index of the first element
      UpperCAmelCase_    :     List[Any]            =	0
      UpperCAmelCase_    :     Dict            =	0




 def __len__(			self							:			Union[str, Any]			)->       int:



      """simple docstring"""

      return self.size




 def 	a   (			self							:			Dict			)->       bool:



      """simple docstring"""

      return self.size == 0




 def 	a   (			self							:			List[Any]			)->       Optional[int]:



      """simple docstring"""

      return False if self.is_empty() else self.array[self.front]




 def 	a   (			self							:			Dict  , a_							:			int			)->       Optional[int]:



      """simple docstring"""

      if self.size >= self.n:
           raise Exception("""QUEUE IS FULL"""			)

      UpperCAmelCase_    :     List[str]            =	data
      UpperCAmelCase_    :     Optional[int]            =	(self.rear + 1) % self.n
      self.size += 1
      return self






 def 	a   (			self							:			Union[str, Any]			)->       List[Any]:



      """simple docstring"""

      if self.size == 0:
           raise Exception("""UNDERFLOW"""			)

      UpperCAmelCase_    :     Tuple            =	self.array[self.front]
      UpperCAmelCase_    :     List[str]            =	None
      UpperCAmelCase_    :     Dict            =	(self.front + 1) % self.n
      self.size -= 1
      return temp

