



import re
from pathlib import Path
from unittest import TestCase

import pytest



@pytest.mark.integration
class 				__snake_case						(     UpperCamelCase_						):




							def    UpperCAmelCase__			(       self     :       List[Any]				,				A_     :       str):

									with open(A_				,				encoding='''utf-8''') as input_file:
											lowerCAmelCase_			:     List[Any]									= re.compile(r'''(?!.*\b(?:encoding|rb|w|wb|w+|wb+|ab|ab+)\b)(?<=\s)(open)\((.*)\)''')
											lowerCAmelCase_			:     Any									= input_file.read()
											lowerCAmelCase_			:     int									= regexp.search(A_)

									return match




							def    UpperCAmelCase__			(       self     :       Optional[int]				,				A_     :       str):

									with open(A_				,				encoding='''utf-8''') as input_file:
											lowerCAmelCase_			:     int									= re.compile(r'''#[^\r\n]*print\(|\"[^\r\n]*print\(|\"\"\".*?print\(.*?\"\"\"|(print\()'''				,				re.DOTALL)
											lowerCAmelCase_			:     Dict									= input_file.read()
											# use `re.finditer` to handle the case where the ignored groups would be matched first by `re.search`
											lowerCAmelCase_			:     Optional[Any]									= regexp.finditer(A_)

									lowerCAmelCase_			:     str									= [match for match in matches if match is not None and match.group(1) is not None]
									return matches[0] if matches else None




							def    UpperCAmelCase__			(       self     :       List[str]):
									lowerCAmelCase_			:     int									= Path('''./datasets''')
									lowerCAmelCase_			:     str									= list(dataset_paths.absolute().glob('''**/*.py'''))

									for dataset in dataset_files:
											if self._no_encoding_on_file_open(str(A_)):
													raise AssertionError(F"""open(...) must use utf-8 encoding in {dataset}""")







							def    UpperCAmelCase__			(       self     :       Dict):
									lowerCAmelCase_			:     Tuple									= Path('''./datasets''')
									lowerCAmelCase_			:     Union[str, Any]									= list(dataset_paths.absolute().glob('''**/*.py'''))

									for dataset in dataset_files:
											if self._no_print_statements(str(A_)):
													raise AssertionError(F"""print statement found in {dataset}. Use datasets.logger/logging instead.""")










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

import torch_xla.distributed.xla_multiprocessing as xmp


def 			UpperCamelCase(  ):
		lowerCAmelCase_			:     List[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(  ):
		lowerCAmelCase_			:     str									= parse_args()

		# Import training_script as a module.
		lowerCAmelCase_			:     str									= Path(args.training_script )
		sys.path.append(str(script_fpath.parent.resolve() ) )
		lowerCAmelCase_			:     Tuple									= script_fpath.stem
		lowerCAmelCase_			:     Union[str, Any]									= importlib.import_module(__UpperCamelCase )

		# Patch sys.argv
		lowerCAmelCase_			:     Optional[int]									= [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()





