






'''simple docstring'''







import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class 					a__    (			A_						):
     '''simple docstring'''







     _snake_case             =  ['''image_processor''', '''tokenizer''']
     _snake_case             =  '''VideoMAEImageProcessor'''
     _snake_case             =  ('''CLIPTokenizer''', '''CLIPTokenizerFast''')






     def __init__(self    :	str				,				lowercase__    :	Tuple=None				,				lowercase__    :	Optional[int]=None				,				**lowercase__    :	Union[str, Any]					)  ->       str:
           __A		   =      None
           if "feature_extractor" in kwargs:
                 warnings.warn(
                     "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
                     " instead."				,				lowercase__				,				)
                 __A		   =      kwargs.pop("feature_extractor"					)

           __A		   =      image_processor if image_processor is not None else feature_extractor
           if image_processor is None:
                 raise ValueError("You need to specify an `image_processor`."					)
           if tokenizer is None:
                 raise ValueError("You need to specify a `tokenizer`."					)

           super().__init__(lowercase__				,				lowercase__					)
           __A		   =      self.image_processor






     def __call__(self    :	Any				,				lowercase__    :	List[Any]=None				,				lowercase__    :	Tuple=None				,				lowercase__    :	List[str]=None				,				**lowercase__    :	Dict					)  ->       Optional[int]:

           if text is None and videos is None:
                 raise ValueError("You have to specify either text or videos. Both cannot be none."					)

           if text is not None:
                 __A		   =      self.tokenizer(lowercase__				,				return_tensors=lowercase__				,				**lowercase__					)

           if videos is not None:
                 __A		   =      self.image_processor(lowercase__				,				return_tensors=lowercase__				,				**lowercase__					)

           if text is not None and videos is not None:
                 __A		   =      image_features.pixel_values
                 return encoding
           elif text is not None:
                 return encoding
           else:
                 return BatchEncoding(data=dict(**lowercase__					)				,				tensor_type=lowercase__					)






     def     _UpperCamelCase   (self    :	Union[str, Any]				,				*lowercase__    :	Optional[int]				,				**lowercase__    :	Union[str, Any]					)  ->       str:
           return self.tokenizer.batch_decode(*lowercase__				,				**lowercase__					)






     def     _UpperCamelCase   (self    :	Tuple				,				*lowercase__    :	List[str]				,				**lowercase__    :	Optional[int]					)  ->       Optional[Any]:
           return self.tokenizer.decode(*lowercase__				,				**lowercase__					)






     @property
     def     _UpperCamelCase   (self    :	int					)  ->       Any:
           return ["input_ids", "attention_mask", "position_ids", "pixel_values"]






     @property
     def     _UpperCamelCase   (self    :	Dict					)  ->       List[str]:
           warnings.warn(
               "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."				,				lowercase__				,				)
           return self.image_processor_class






     @property
     def     _UpperCamelCase   (self    :	Optional[Any]					)  ->       Tuple:
           warnings.warn(
               "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."				,				lowercase__				,				)
           return self.image_processor









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

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

      return parser.parse_args()


def 						_UpperCamelCase							(     ):
      __A		   =      parse_args()

      # Import training_script as a module.
      __A		   =      Path(args.training_script							)
      sys.path.append(str(script_fpath.parent.resolve()							)							)
      __A		   =      script_fpath.stem
      __A		   =      importlib.import_module(snake_case__							)

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


