



'''simple docstring'''

import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

snake_case_			=     logging.getLogger()






def       __lowercase  (_SCREAMING_SNAKE_CASE      :str       ):
				SCREAMING_SNAKE_CASE  :						Optional[int]      					= {}
				SCREAMING_SNAKE_CASE  :						Tuple      					= os.path.join(_SCREAMING_SNAKE_CASE    ,	'''all_results.json'''       )
				if os.path.exists(_SCREAMING_SNAKE_CASE       ):
								with open(_SCREAMING_SNAKE_CASE    ,	'''r'''       ) as f:
												SCREAMING_SNAKE_CASE  :						List[str]      					= json.load(_SCREAMING_SNAKE_CASE       )
				else:
								raise ValueError(F'''can\'t find {path}'''       )
				return results


snake_case_			=     logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)




@require_torch_tpu
class 	a__     (				_lowercase	):


	def 				lowercase__  (self : Optional[Any]      )     ->			Union[str, Any]:

					"""simple docstring"""

					import xla_spawn

					SCREAMING_SNAKE_CASE  :						Dict      					= self.get_auto_remove_tmp_dir()
					SCREAMING_SNAKE_CASE  :						int      					= F'''
            ./examples/pytorch/text-classification/run_glue.py
            --num_cores=8
            ./examples/pytorch/text-classification/run_glue.py
            --model_name_or_path distilbert-base-uncased
            --output_dir {tmp_dir}
            --overwrite_output_dir
            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv
            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv
            --do_train
            --do_eval
            --debug tpu_metrics_debug
            --per_device_train_batch_size=2
            --per_device_eval_batch_size=1
            --learning_rate=1e-4
            --max_steps=10
            --warmup_steps=2
            --seed=42
            --max_seq_length=128
            '''.split()

					with patch.object(__UpperCAmelCase,					'''argv''',					__UpperCAmelCase      ):
									SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= time()
									xla_spawn.main()
									SCREAMING_SNAKE_CASE  :						Dict      					= time()

									SCREAMING_SNAKE_CASE  :						Optional[int]      					= get_results(__UpperCAmelCase      )
									self.assertGreaterEqual(result['''eval_accuracy'''],					0.75      )

									# Assert that the script takes less than 500 seconds to make sure it doesn't hang.
									self.assertLess(end - start,					500      )






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

					"""simple docstring"""

					import xla_spawn

					SCREAMING_SNAKE_CASE  :						int      					= '''
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            '''.split()
					with patch.object(__UpperCAmelCase,					'''argv''',					__UpperCAmelCase      ):
									xla_spawn.main()









'''simple docstring'''

from ..utils import DummyObject, requires_backends


class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Dict	    =     ["torch", "transformers", "onnx"]


	def __init__(self : List[str],					*__UpperCAmelCase : Dict,					**__UpperCAmelCase : List[Any]      )     ->			Union[str, Any]:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Optional[Any],					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : int      )     ->			int:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Any,					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : Tuple      )     ->			Tuple:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Any	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Dict,					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Optional[Any]      )     ->			int:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Any,					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : List[str]      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : int,					*__UpperCAmelCase : List[Any],					**__UpperCAmelCase : Any      )     ->			Optional[Any]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[Any]	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Dict,					*__UpperCAmelCase : Dict,					**__UpperCAmelCase : Any      )     ->			List[str]:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Tuple,					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : int      )     ->			Optional[Any]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Union[str, Any],					*__UpperCAmelCase : List[str],					**__UpperCAmelCase : str      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Tuple	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Union[str, Any],					*__UpperCAmelCase : Optional[int],					**__UpperCAmelCase : List[Any]      )     ->			Tuple:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : str,					*__UpperCAmelCase : Optional[int],					**__UpperCAmelCase : Tuple      )     ->			str:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : int,					*__UpperCAmelCase : List[Any],					**__UpperCAmelCase : List[str]      )     ->			Tuple:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[Any]	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Dict,					*__UpperCAmelCase : Optional[Any],					**__UpperCAmelCase : int      )     ->			List[str]:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : List[str],					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Dict      )     ->			Union[str, Any]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Any,					*__UpperCAmelCase : List[str],					**__UpperCAmelCase : List[Any]      )     ->			Dict:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Dict	    =     ["torch", "transformers", "onnx"]


	def __init__(self : Tuple,					*__UpperCAmelCase : Optional[Any],					**__UpperCAmelCase : List[str]      )     ->			Any:

					"""simple docstring"""

					requires_backends(self,					['''torch''', '''transformers''', '''onnx''']      )


	@classmethod
	def 				lowercase__  (cls : Tuple,					*__UpperCAmelCase : Any,					**__UpperCAmelCase : Union[str, Any]      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )






	@classmethod
	def 				lowercase__  (cls : Optional[Any],					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Optional[Any]      )     ->			int:

					"""simple docstring"""

					requires_backends(cls,					['''torch''', '''transformers''', '''onnx''']      )




