


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)

lowerCAmelCase__			:      Union[str, Any]								=logging.getLogger()






def 						a__			(				A__				):
			SCREAMING_SNAKE_CASE_		:     str					=					{}
			SCREAMING_SNAKE_CASE_		:     List[Any]					=					os.path.join(__lowerCamelCase,      'all_results.json'				)
			if os.path.exists(__lowerCamelCase				):
						with open(__lowerCamelCase,      'r'				) as f:
									SCREAMING_SNAKE_CASE_		:     Dict					=					json.load(__lowerCamelCase				)
			else:
						raise ValueError(F'''can\'t find {path}'''				)
			return results


lowerCAmelCase__			:      Any								=logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)







@require_torch_tpu
class 	__lowercase    (_SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										import xla_spawn

										SCREAMING_SNAKE_CASE_		:     Dict					=					self.get_auto_remove_tmp_dir()
										SCREAMING_SNAKE_CASE_		:     int					=					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(_lowercase			,						'argv'			,						_lowercase       ):
													SCREAMING_SNAKE_CASE_		:     Dict					=					time()
													xla_spawn.main()
													SCREAMING_SNAKE_CASE_		:     Any					=					time()

													SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					get_results(_lowercase       )
													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			,						5_0_0       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										import xla_spawn

										SCREAMING_SNAKE_CASE_		:     List[Any]					=					'\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            '.split()
										with patch.object(_lowercase			,						'argv'			,						_lowercase       ):
													xla_spawn.main()







'''simple docstring'''



from .testing import (
    are_the_same_tensors,
    execute_subprocess_async,
    require_bnb,
    require_cpu,
    require_cuda,
    require_huggingface_suite,
    require_mps,
    require_multi_gpu,
    require_multi_xpu,
    require_safetensors,
    require_single_gpu,
    require_single_xpu,
    require_torch_min_version,
    require_tpu,
    require_xpu,
    skip,
    slow,
)
from .training import RegressionDataset, RegressionModel, RegressionModelaXPU


from .scripts import test_script, test_sync, test_ops  # isort: skip
