




"""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    (			)			->			List[str]:


			"""simple docstring"""
			__UpperCAmelCase	: 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    (			)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: List[Any]		=					parse_args()

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

			# Patch sys.argv
			__UpperCAmelCase	: 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()








"""simple docstring"""





from ...processing_utils import ProcessorMixin



class      a__				(	__magic_name__   ):
			lowercase_    =	["image_processor", "feature_extractor"]
			lowercase_    =	"TvltImageProcessor"
			lowercase_    =	"TvltFeatureExtractor"


			def __init__(      self      :    Tuple      ,  UpperCamelCase_      :    Optional[int]      ,  UpperCamelCase_      :    Dict):


						"""simple docstring"""




						super().__init__(image_processor=UpperCamelCase_      ,  feature_extractor=UpperCamelCase_)

						__UpperCAmelCase	: Optional[int]		=					image_processor
						__UpperCAmelCase	: Dict		=					feature_extractor


			def __call__(      self      :    Tuple      ,  UpperCamelCase_      :    str=None      ,  UpperCamelCase_      :    Optional[int]=None      ,  UpperCamelCase_      :    Optional[int]=None      ,  UpperCamelCase_      :    str=None      ,  UpperCamelCase_      :    List[str]=False      ,  UpperCamelCase_      :    Optional[int]=False      ,  *UpperCamelCase_      :    List[str]      ,  **UpperCamelCase_      :    str      ,  ):


						"""simple docstring"""




						if images is None and audio is None:
									raise ValueError("You need to specify either an `images` or `audio` input to process.")

						__UpperCAmelCase	: Optional[Any]		=					None
						if images is not None:
									__UpperCAmelCase	: int		=					self.image_processor(UpperCamelCase_      ,  mask_pixel=UpperCamelCase_      ,  *UpperCamelCase_      ,  **UpperCamelCase_)
						if images_mixed is not None:
									__UpperCAmelCase	: int		=					self.image_processor(UpperCamelCase_      ,  is_mixed=UpperCamelCase_      ,  *UpperCamelCase_      ,  **UpperCamelCase_)
						if audio is not None:
									__UpperCAmelCase	: List[Any]		=					self.feature_extractor(
									    UpperCamelCase_      ,  *UpperCamelCase_      ,  sampling_rate=UpperCamelCase_      ,  mask_audio=UpperCamelCase_      ,  **UpperCamelCase_)

						__UpperCAmelCase	: List[str]		=					{}
						if audio is not None:
									output_dict.update(UpperCamelCase_)
						if images is not None:
									output_dict.update(UpperCamelCase_)
						if images_mixed_dict is not None:
									output_dict.update(UpperCamelCase_)
						return output_dict


			@property
			def       a_     (      self      :    str):


						"""simple docstring"""




						__UpperCAmelCase	: List[Any]		=					self.image_processor.model_input_names
						__UpperCAmelCase	: List[Any]		=					self.feature_extractor.model_input_names
						return list(dict.fromkeys(image_processor_input_names + feature_extractor_input_names))


