



"""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)

a_       =       logging.getLogger()







def 				SCREAMING_SNAKE_CASE__   (		SCREAMING_SNAKE_CASE__			:	Optional[Any]      ):



					"""simple docstring"""





					snake_case_       :		List[Any]			       =       {}
					snake_case_       :		Dict			       =       os.path.join(__UpperCAmelCase					,     """all_results.json"""      )
					if os.path.exists(__UpperCAmelCase      ):
										with open(__UpperCAmelCase					,     """r"""      ) as f:
															snake_case_       :		Dict			       =       json.load(__UpperCAmelCase      )
					else:
										raise ValueError(f'can\'t find {path}'      )
					return results


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







@require_torch_tpu
class  __lowercase  (       _UpperCAmelCase):







						"""simple docstring"""







						def     __UpperCamelCase				(self							):
											import xla_spawn

											snake_case_       :		Optional[int]			       =       self.get_auto_remove_tmp_dir()
											snake_case_       :		Any			       =       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(a_ ,		"""argv""" ,		a_							):
																snake_case_       :		str			       =       time()
																xla_spawn.main()
																snake_case_       :		Optional[Any]			       =       time()

																snake_case_       :		List[str]			       =       get_results(a_							)
																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_00							)







						def     __UpperCamelCase				(self							):
											import xla_spawn

											snake_case_       :		Optional[Any]			       =       '\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            '.split()
											with patch.object(a_ ,		"""argv""" ,		a_							):
																xla_spawn.main()









'''simple docstring'''

import os


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_doctest_list.py
a							   =				'.'


if __name__ == "__main__":
	a							   =				os.path.join(REPO_PATH, 'utils/documentation_tests.txt')
	a							   =				[]
	a							   =				[]
	with open(doctest_file_path) as fp:
		for line in fp:
			a							   =				line.strip()
			a							   =				os.path.join(REPO_PATH, line)
			if not (os.path.isfile(path) or os.path.isdir(path)):
				non_existent_paths.append(line)
			all_paths.append(path)
	if len(non_existent_paths) > 0:
		a							   =				'\n'.join(non_existent_paths)
		raise ValueError(F"""`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}""")
	if all_paths != sorted(all_paths):
		raise ValueError('Files in `utils/documentation_tests.txt` are not in alphabetical order.')




