




'''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   :   Any     							=	logging.getLogger()
def 	snake_case_					(UpperCamelCase :						Union[str, Any]   ):





							'''simple docstring'''


							_a			  =       {}
							_a			  =       os.path.join(UpperCamelCase				,		'''all_results.json'''   )
							if os.path.exists(UpperCamelCase   ):
														with open(UpperCamelCase				,		'''r'''   ) as f:
																					_a			  =       json.load(UpperCamelCase   )
							else:
														raise ValueError(f'can\'t find {path}'   )
							return results


_snake_case   :   Optional[int]     							=	logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)

@require_torch_tpu
class     A					(	_a					):







							def      __lowerCAmelCase    (						self :						Any      )    ->							Dict:


														"""simple docstring"""


														import xla_spawn

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

														with patch.object(lowerCAmelCase_							,    '''argv'''							,    lowerCAmelCase_      ):
																					_a			  =       time()
																					xla_spawn.main()
																					_a			  =       time()

																					_a			  =       get_results(lowerCAmelCase_      )
																					self.assertGreaterEqual(result['''eval_accuracy''']							,    0.7_5      )

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







							def      __lowerCAmelCase    (						self :						Dict      )    ->							Optional[Any]:


														"""simple docstring"""


														import xla_spawn

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







'''simple docstring'''


import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
				import ctypes
				import msvcrt  # noqa

				class     A					(	ctypes.Structure					):
											# _fields is a specific attr expected by ctypes
											lowercase_           =       [('size', ctypes.c_int), ('visible', ctypes.c_byte)]
def 	snake_case_					():





							'''simple docstring'''


							if os.name == "nt":
														_a			  =       CursorInfo()
														_a			  =       ctypes.windll.kernelaa.GetStdHandle(-11   )
														ctypes.windll.kernelaa.GetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
														_a			  =       False
														ctypes.windll.kernelaa.SetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
							elif os.name == "posix":
														sys.stdout.write('''\033[?25l'''   )
														sys.stdout.flush()
def 	snake_case_					():





							'''simple docstring'''


							if os.name == "nt":
														_a			  =       CursorInfo()
														_a			  =       ctypes.windll.kernelaa.GetStdHandle(-11   )
														ctypes.windll.kernelaa.GetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
														_a			  =       True
														ctypes.windll.kernelaa.SetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
							elif os.name == "posix":
														sys.stdout.write('''\033[?25h'''   )
														sys.stdout.flush()

@contextmanager
def 	snake_case_					():





							'''simple docstring'''


							try:
														hide_cursor()
														yield
							finally:
														show_cursor()

